1

I have this code:

$xml_response = $linkedin->getProfile("~:(id,firstName,lastName,email-address)");

which generates the following result xml:

<person>
<id>c3g9fdgdbP9-</id>
<first-name>Shoen</first-name>
<last-name>Vergue</last-name>
<email-address>manager@glob....beg.com</email-address>
</person>

How to get for example email value?

I tried this:

$mail=$xml_response['email-address'];

but it returns nothing

Thank you in advance

thecore7
  • 484
  • 2
  • 8
  • 29
  • 1
    [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php?rq=1) – har07 Jan 25 '16 at 12:14

1 Answers1

1

Check out the SimpleXML Parser, and try something like this:

libxml_use_internal_errors(true);

$xml = simplexml_load_string($xml_response);
if ($xml === false) {
    echo "Failed loading XML: ";
    foreach(libxml_get_errors() as $error) {
        echo "<br>", $error->message;
    }
} else {
    echo $xml->{"email-address"};
}
MTCoster
  • 5,868
  • 3
  • 28
  • 49
  • Thanks for helping me MTCoster but it returns 0 for echo $xml->email-address; When I var_dump($xml); in else I can see this: object(SimpleXMLElement)#6 (4) { ["id"]=> string(10) "c3g9fdgdbP9-" ["first-name"]=> string(6) "Shoen" ["last-name"]=> string(7) "Vergue" ["email-address"]=> string(21) "manager@glob....beg.com" } 0 – thecore7 Jan 25 '16 at 12:23
  • 1
    After I change it to echo $xml->{'email-address'}; it worked ! Thank you so much MTCoster :) – thecore7 Jan 25 '16 at 12:28
  • @thecore7 Glad to hear it! I'll update the answer to reflect this – MTCoster Jan 25 '16 at 12:29