How to extract following xml using PHP




<id>rfBRFK4d1s</id>
<first-name>Thamaraiselvam</first-name>
<last-name>T</last-name>
<headline>Software Development Intern at Snowman Branding Services Pvt. Ltd</headline>
<picture-url>http://ift.tt/1yPKBAc;
<industry>Computer Software</industry>
<connections total="771" count="767" start="0">
<person>
<id>Fvq7UCM43W</id>
<first-name>Mike</first-name>
<last-name>Ryan</last-name>
<headline>CEO / Advisor / VC Backed Startups @mikegordonryan</headline>
<picture-url>http://ift.tt/19qESw1;
<api-standard-profile-request>
<url>http://ift.tt/1yPKBAe;
<headers total="1">
<http-header>
<name>x-li-auth-token</name>
<value>name:LOn8</value>
</http-header>
</headers>
</api-standard-profile-request>
<site-standard-profile-request>
<url>http://ift.tt/19qEUnu;
</site-standard-profile-request>
<location>
<name>San Francisco Bay Area</name>
<country>
<code>us</code>
</country>
</location>
<industry>Information Technology and Services</industry>
</person>
<person>
<id>fvab8bjKXC</id>
<first-name>Krishna</first-name>
<last-name>Murari</last-name>
<headline>PHP Web Developer at Unified Media Marketing Group</headline>
<picture-url>http://ift.tt/1yPKB3j;
<api-standard-profile-request>
<url>http://ift.tt/19qEUnw;
<headers total="1">
<http-header>
<name>x-li-auth-token</name>
<value>name:oBCf</value>
</http-header>
</headers>
</api-standard-profile-request>
<site-standard-profile-request>
<url>http://ift.tt/1yPKBAg;
</site-standard-profile-request>
<location>
<name>New Delhi Area, India</name>
<country>
<code>in</code>
</country>
</location>
<industry>Internet</industry>
</person>


I'm trying to extract above xml using PHP and i tried with following code



$xml_response="my xml contents";
$xml = simplexml_load_string($xml_response);
echo $xml->person[0]['headers'] . "<br>";
echo $xml->id;


I can get id but i cannot get other things and



echo $xml->first-name;


it shows error because of that - between first and name then i have so many category like person details how do i create loop for that to retrieve?


No comments:

Post a Comment