从字符串中提取lat和lon [复制]

This question already has an answer here:

I have got the following string

http://www.domain.com/map.aspx?isTrafficAlert=true&lat=51.529900&lon=-0.785384

I need to extract lat and lon from this string.

I got lat=51.529900 and lon=-0.785384 using the following code

$str = "http://www.domain.com/map.aspx?isTrafficAlert=true&lat=51.529900&lon=-0.785384";
list(,$lat,$lon) = explode("&",$str);

But then can't get the number.

Any help is highly appreciated. Thanks in advance.

</div>

You can use parse_str along with parse_url like as

parse_str(parse_url($str, PHP_URL_QUERY), $latlon);
echo $latlon['lat'];
echo $latlon['lon'];
$str = "http://www.domain.com/map.aspx?isTrafficAlert=true&lat=51.529900&lon=-0.785384";

$var = parse_str($str, $array);

$lat = $array['lat'];
$lon = $array['lon'];

Try this:

$str = "http://www.domain.com/map.aspx?isTrafficAlert=true&lat=51.529900&lon=-0.785384";

parse_str($str,$params);
print_r($params);

LAT: $params['lat']; LON: $params['lon'];

Hope it help;