This question already has an answer here:
- How to parse CDATA HTML-content of XML using SimpleXML? 2 answers
Im trying to get an img url from <content:encoded>
and inserting the url into my DB
But i can't seem to get correct information from the xml file-
or is it not possible to retrive the data with simpleXML?
This is my XML
<item>
<title>Movietitle</title>
<content:encoded><![CDATA[<p>
<img class="aligncenter wp-image-22085" src="movie-poster-694x1024.jpg" alt="Predestination 2014" width="475" height="701" /></p>
<p><span id="more-22087"></span></p>
<p>
<a href="http://bit.ly/1za5mIz" target="_blank">
<h4 style="text-align: left;">Release Info:</h4>
Genre: Sci-Fi, Thriller<br />
Quality: DVDRip<br />
Language: English</p>]]>
</content:encoded>
</item>
PHP
$feeds = array('http://xxxx.xml');
foreach( $feeds as $feed ) {
$xml = simplexml_load_file($feed);
foreach($xml->channel->item as $item) {
$video_title = $item->title;
$video_img=(string) $item->children($ns['content']);
$sql = "INSERT INTO video (video_title, video_img, video_date) VALUES (:video_title, :video_img, NOW())";
$query = $dbh->prepare($sql);
$query->execute(array(
':video_title' => $video_title,
':video_img' => $video_img
));
}
}