简体   繁体   中英

PHP Reading XML Issue

I need your help once again!

I need to read this xml file... but the problem is that it's not working!

This is the XML

<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<item>
<title>Video</title>
<media:content url="http://videourl.com/etc/" type="video/x-flv" duration="5128"/>
</item>
</channel>
</rss>

And this is my code:

<?php
$xml=simplexml_load_file("http://videourl.com/etc/");
echo $xml->getName() . "<media:content url=";

foreach($xml->children() as $child)
  {
  echo $child->getName() . ": " . $child . "";
  }

?>

And it's not working! It's not working because nothing gets echoed, or printed! Does anyone spot the error?

<?php 
$xml = '<?xml version="1.0" encoding="UTF-8" ?> 
<rss> 
    <channel> 
        <item> 
            <title><![CDATA[Tom & Jerry]]></title> 
        </item> 
    </channel> 
</rss>'; 

$xml = simplexml_load_string($xml); 

// echo does the casting for you 
echo $xml->channel->item->title; 

// but vardump (or print_r) not! 
var_dump($xml->channel->item->title); 

// so cast the SimpleXML Element to 'string' solve this issue 
var_dump((string) $xml->channel->item->title); 
?> 

Again i edit my code now try this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM