2 Votes Vote

difference in reading XML from source code manually copied and programitically generated by PHP

Posted by topdog 26 days ago Questions| content php generated All

I did PHP coding using an XML file whose source code I copied manually, it looks like

<title type='text'>content I've extracted</title>
<content type='text'>content I've extracted</content>

Now everything is done and when I generate the content by PHP coding and when I try to extract the things from title and content tags the output is not generated...when I cross checked I found the PHP generated file (source code, RSS feed)looks like

<title type=\'text\'>content to be extracted </title>
<content type=\'text\'>content to be extracted</content>

As there are backward slashes it is not able to extract the content, I guess

The sample PHP code which I'm using to get contents from those tags is

  $titles = $entry->getElementsByTagName( "title" );
  $title = $titles->item(0)->nodeValue;

  $descrs = $entry->getElementsByTagName( "content" );
  $descr = $descrs->item(0)->nodeValue;

Can someone please suggest me how I can proceed

This is the PHP code which I used to generate XML

$url='http://gdata.youtube.com/feeds/api/playlists/12345';
$fp = fopen($url, 'r'); 
$buffer='';
if ($fp) {
while (!feof($fp))
$buffer .= fgets($fp, 1024);
fclose($fp);
file_put_contents('feed.xml', $buffer);

I found the solution

$buff=stripslashes($buffer);
file_put_contents('ka.xml', $buff);

so stripslashes() function removes backslash and it works

Originally asked by: pbvamsi on Stack Overflow

Discuss Bury


Who Voted for this Question