URL変数を持つphpファイルがあります
$url = "http://nominatim.openstreetmap.org/reverse?`format=xml&lat=31.130948&lon=-94.470355&addressdetails=1";`
以下のコードで URL を送信します。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
同じphpファイルで応答を受け取り、各XMLアイテムを変数に入れるにはどうすればよいですか?
nominatim サーバーからの応答は非常に長い XML ファイルです。以下のように小さな部分だけを処理する必要があります。
<addressparts>
<road>County Road 357</road>
<hamlet>Nancy</hamlet>
<county>Angelina County</county>
<state>Texas</state>
<country>United States of America</country>
<country_code>us</country_code>
</addressparts>