アーロンが示唆したように。車輪の再発明をしないのが最善なので、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 );
これで、$ xml変数の任意の部分にオブジェクトとしてアクセスできるようになりました。これは、投稿した内容の例です。
<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>
これで、このXML文字列をsimplexml_load_string()にロードした後、そのように応答のIPアドレスにアクセスできます。
$xml->IP;
simplexml_load_string()は、整形式のXMLファイルを操作可能なオブジェクトに変換します。私が言える他の唯一のことは、行って試してみて遊ぶことです
編集:
ソース
http://www.php.net/manual/en/function.simplexml-load-string.php