I am writing that post because i'm trying to solve a problem which seems to be stupid but unfortunately i cannot make it. I have an XML file (link) which i'm parsing with simplexml_load_string($link) as below:
$response_xml_data = file_get_contents($link);
$xml = simplexml_load_string($response_xml_data);
foreach ($xml->item as $licenseElement) {
$title = $licenseElement->title;
echo $title;
}
I need to get value of title
and link
but no any result.
I try to print $link
and show me this :
SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 2.0
)
[channel] => SimpleXMLElement Object
(
[title] => GamePlay
[link] => https://example.com/
[description] => The latest blog posts from example.com.
[language] => en-us
[pubDate] => Mon, 14 Nov 2016 18:50:50 +0000
[lastBuildDate] => Mon, 14 Nov 2016 18:50:50 +0000
[managingEditor] => info@example.com
[item] => SimpleXMLElement Object
(
[title] => IO Interactive
[link] => http://example.com/?p=258
)
)
)
UPDATE: When try to var_dump($xml); before loop :
object(SimpleXMLElement)#2568 (2) {
["@attributes"]=>
array(1) {
["version"]=>
string(3) "2.0"
}
["channel"]=>
object(SimpleXMLElement)#2571 (8) {
["title"]=>
string(8) "Gameplay"
["link"]=>
string(21) "https://example.com/"
["description"]=>
string(40) "The latest blog posts from example.com."
["language"]=>
string(5) "en-us"
["pubDate"]=>
string(31) "Mon, 14 Nov 2016 19:08:33 +0000"
["lastBuildDate"]=>
string(31) "Mon, 14 Nov 2016 19:08:33 +0000"
["managingEditor"]=>
string(17) "info@example.com"
["item"]=>
object(SimpleXMLElement)#2574 (2) {
["title"]=>
string(76) "IO Interactive "
["link"]=>
string(217) "http://example.com/?p=258"
}
}
}