さて、あなたが持っているものに見えることを行うことができますどのように教えてください。それらを削除すると、json_decodeを使用して文字列をPHP stdClass
オブジェクトにデコードし、その値にアクセスできます。 、それは大まかな答えだ再び
$result = ' ?({"ip":"104.112.115.28","country_code":"US","country_name":"United States","region_code":"CA","region_name":"California","city":"Houston","zip_code":"90013","time_zone":"America/Los_Angeles","latitude":34.0453,"longitude":-118.2413,"metro_code":803});';
//remove the bad stuff on the start and end, which assumes these strings don't exist elsewhere in the result, which is a pretty big assumption
$string = str_replace('?({', '{', str_replace('});', '}', trim($result));
$data = json_decode($string);
echo $data->ip;
と大きな前提になりますが、それはおそらく、ほとんどのケースの下で動作します;:
ぞんざいに行われ、あなたのような何かを試みることができます確かにあなたが与えた例のために。
JSONとほとんど同じように見えるので、json_decodeをほとんど使用することができます。 –
この出力をどのように取得しているかを示す情報を少し追加できますか? –
$ decodedJson = json_decode($ data、true); foreach($ decodedJson $値){ echo $ value ['region_name']; エコー "
"; } – Parag