-1

This is my code snippet:

$feed=file_get_contents($feed);
$feed=simplexml_load_string($feed);

I have tried all the solutions here but nothing works.It actually works for one feed and not the other.If another solution is used the other one works but the older one fails.Please help me fix this.It's irritating.I need a universal solution.

Community
  • 1
  • 1
user1633170
  • 11
  • 2
  • 13

1 Answers1

0

Try this:

 $feed=file_get_contents($feed);
 $feed=str_replace(chr(hexdec('20')),' ', $feed);
 $feed=str_replace(chr(hexdec('5D')), ']', $feed);
 $feed=simplexml_load_string($feed);

Actually each hex(0x) entry in the error corresponds to a symbol use str_replace to replace the characters and then try simplexml_load_string.Use this link for conversion purpose.I am surprised not to see this easy method else where in this forum.Hope this helps you.

user1613360
  • 1,280
  • 3
  • 16
  • 42
  • If he receives a pile of garbage, just stripping the first four chars won't make the remainder valid XML. – mario Sep 29 '12 at 22:02
  • Thank you very much it works.@mario I am using news feeds from highly rated sites so there is no chance of getting garbage and moreover the problem is with encoding types I use UTF-8.Anyways thank you for the suggestion. – user1633170 Sep 29 '12 at 22:05