Comme Aaron l'a suggéré. Mieux vaut ne pas réinventer la roue, alors essayez l'analyse syntaxique avec simplexml_load_string()
// Init the CURL
$curl = curl_init();
// Setup the curl settings
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
// grab the XML file
$raw_xml = curl_exec($curl);
curl_close($curl);
// Setup the xml object
$xml = simplexml_load_string($raw_xml);
Vous pouvez désormais accéder à une partie de la variable $ xml comme un objet, dans cet égard est ici un exemple de ce que vous avez publié.
<Response>
<Ip>74.125.45.100</Ip>
<Status>OK</Status>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<RegionCode>06</RegionCode>
<RegionName>California</RegionName>
<City>Mountain View</City>
<ZipPostalCode>94043</ZipPostalCode>
<Latitude>37.4192</Latitude>
<Longitude>-122.057</Longitude>
<Timezone>0</Timezone>
<Gmtoffset>0</Gmtoffset>
<Dstoffset>0</Dstoffset>
</Response>
maintenant après avoir chargé cette chaîne XML dans le simplexml_load_string(), vous pouvez accéder à l'adresse IP de la réponse comme ceci. Simplexml_load_string() va transformer des fichiers XML bien formés en un objet que vous pouvez manipuler. La seule autre chose que je peux dire est aller l'essayer et jouer avec
EDIT:
Source http://www.php.net/manual/en/function.simplexml-load-string.php
Ou simplement: '$ xml = simplexml_load_file ($ url);' – salathe
Sémantique ;-) il était le seul exemple de travail réel que j'avais autour de la pose – WarmWaffles