【问题标题】:PHP Store array valuesPHP 存储数组值
【发布时间】:2014-05-06 10:43:06
【问题描述】:

您好,我正在使用 maxmind minfraud。我得到了这样的结果:

err=;countryCode=IN;ip_region=25;ip_city=;ip_latitude=10.0223;ip_longitude=30.2433;highRiskCountry=No;queriesRemaining=1075;cityPostalMatch=;shipCityPostalMatch=;ip_domain=;ip_countryName=;ip_continentCode=AS;ip_corporateProxy =No;shipForward=NA;riskScore=0.20;prepaid=;minfraud_version=1.3

这里我想作为数组值返回。

<?php

function fraudQuery($ip, $country_code, $state, $city, $area_code, $mail_domain,$address)
{
 $d = file_get_contents("https://minfraud.maxmind.com/app/ccv2r?license_key=".IP_LOOKUP_KEY."&i=$ip&country=$country_code&city=$city&postal=$area_code&domain=$mail_domain&shipAddr=$address&shipCity=$city&shipRegion=$state&shipPostal=$area_code&shipCountry=$country_code");

 return array('Errors' =>err,  'IpCountryCode' => countryCode, 'IpCountry' => ip_countryName, 'IpRegionCode' => ip_region, 'IpRegion' => ip_regionName, 'IpCity' => ip_city, 'IpHostName' => ip_domain, 'Score' => riskScore);

}
?>

如何像这样返回数组值。谢谢

【问题讨论】:

  • 您需要将结果分解为;,然后再次分解为=,这应该会得到所需的结果。

标签: php arrays function output


【解决方案1】:

使用parse_str()

parse_str(str_replace(';','&',$yourresultfromURL),$matcharray);

Demonstration


解释:

; 替换为&amp; 以便将其转换为parse_str 格式,最后将这些匹配项移至$matcharray 数组。

【讨论】:

    猜你喜欢
    • 2020-09-15
    • 1970-01-01
    • 2011-07-26
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2013-10-24
    • 1970-01-01
    • 2016-02-20
    相关资源
    最近更新 更多