simplexml_load_file problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newzdog
    New Member
    • Oct 2009
    • 2

    simplexml_load_file problem

    Hi,

    I have a problem parsing an rss feed using simplexml_load_ file - this is strange as i have used the same code to parse literally 1000s of different rss feeds in the past, and even stranger in that if i put the feed source on our server as a .xml file then my code parses it successfully.

    The relevant code snippet:
    Code:
    $xml = simplexml_load_file("http://www.quidco.com/blog/?feed=rss2",'SimpleXMLElement', LIBXML_NOCDATA);
    The errors i get are:
    Warning: simplexml_load_ file() [function.simple xml-load-file]: http://www.quidco.com/blog/?feed=rss2:1: parser error : Start tag expected, '<' not found in [my php script]
    Warning: simplexml_load_ file() [function.simple xml-load-file]: 2977 in [my php script]
    Warning: simplexml_load_ file() [function.simple xml-load-file]: ^ in [my php script]
    Any ideas or suggestions will be much appreciated thanks.
    d.
    Last edited by Dormilich; Oct 22 '09, 03:41 PM. Reason: Please use [code] tags when posting code
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I'm stumped on this one. I don't get the same error as you.. I get:

    Code:
    Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.quidco.com/blog/?feed=rss2:76: parser error : expected '>' in C:\xampp\htdocs\index.php on line 3
    
    Warning: simplexml_load_file() [function.simplexml-load-file]: <link>http://www.quidco.com/blog/?p=365</li	 <comments>http://www.quidco.com/b in C:\xampp\htdocs\index.php on line 3
    
    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3
    
    Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.quidco.com/blog/?feed=rss2:76: parser error : Opening and ending tag mismatch: link line 76 and li in C:\xampp\htdocs\index.php on line 3
    
    Warning: simplexml_load_file() [function.simplexml-load-file]: <link>http://www.quidco.com/blog/?p=365</li	 <comments>http://www.quidco.com/b in C:\xampp\htdocs\index.php on line 3
    
    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3
    
    Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.quidco.com/blog/?feed=rss2:327: parser error : Extra content at the end of the document in C:\xampp\htdocs\index.php on line 3
    
    Warning: simplexml_load_file() [function.simplexml-load-file]: 0 in C:\xampp\htdocs\index.php on line 3
    
    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3

    Comment

    • newzdog
      New Member
      • Oct 2009
      • 2

      #3
      Markus,
      Thanks for the reply. I've just tried loading the content to a local file via file_get_conten ts and have realised that it's a data problem - there are various control characters (e.g ^M) at the start and end of the xml. Previously i'd just copied the source from Firefox so hadn't seen those characters. Now i just have to figure out whether i can remove them, or persuade quidco to remove them. Thanks again.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by newzdog
        Markus,
        Thanks for the reply. I've just tried loading the content to a local file via file_get_conten ts and have realised that it's a data problem - there are various control characters (e.g ^M) at the start and end of the xml. Previously i'd just copied the source from Firefox so hadn't seen those characters. Now i just have to figure out whether i can remove them, or persuade quidco to remove them. Thanks again.
        I'd tell the site to produce valid XML :D

        Comment

        • JoBlo

          #5
          Have often encountered this problem, this regex should fix the data:

          $output = preg_replace('/[\x00-\x09\x0B\x0C\x0 E-\x1F\x7F]/', '', $input);

          It removes all control characters except new lines and carriage returns.

          Comment

          Working...