-2

i am getting this result from my linked in connect script,

<person>
  <email-address>xzenia1@gmail.com</email-address>
  <picture-url>http://m3.licdn.com/mpr/mprx/0_UiHHf6SiF4yuBerHUkfUfkshFpomUIrHMbpBf5Iy4sOYk7FecL4XTLxtdAEl42AXsho9hGzDtRBl</picture-url>
</person>

this is the php call

$xml_response = $linkedin->getProfile("~:(email-address,picture-url)");

how to make them assign to separate PHP variable.

Fabio
  • 23,183
  • 12
  • 55
  • 64

3 Answers3

1

You can load your xml as string with simplexml_load_string and then loop in it to get all data

$xml = simplexml_load_string($xml_response);
foreach($xml as $key => $val)
{
    echo "$key=>$val<br>" . "\n";
}

This will output

email-address=>xzenia1@gmail.com
picture-url=>http://m3.licdn.com/mpr/mprx/0_UiHHf6SiF4yuBerHUkfUfkshFpomUIrHMbpBf5Iy4sOYk7FecL4XTLxtdAEl42AXsho9hGzDtRBl

Live sample

Fabio
  • 23,183
  • 12
  • 55
  • 64
0

Try,

    $xml = (array)simplexml_load_string($xml_response);

    echo  $email=$xml['email-address'];
    echo $picture=$xml['picture-url'];
Shijin TR
  • 7,516
  • 10
  • 55
  • 122
0
$xml = simplexml_load_string($linkedin->getProfile("~:(email-address,picture-url)"));

echo $xml->{'email-address'}[0] . "<br />";
echo $xml->{'picture-url'}[0];

simplexmldoesn't like - in node names, therefore use $xml->{'email-address'} instead of $xml->email-address.

use index [0] on both nodes, just in case, if one day your simplexml object would contain more than one <person> node...

see it working: http://codepad.viper-7.com/dQQ6sa

michi
  • 6,565
  • 4
  • 33
  • 56