473,387 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. $xml = simplexml_load_file("http://www.quidco.com/blog/?feed=rss2",'SimpleXMLElement', LIBXML_NOCDATA);
The errors i get are:
Warning: simplexml_load_file() [function.simplexml-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.simplexml-load-file]: 2977 in [my php script]
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in [my php script]
Any ideas or suggestions will be much appreciated thanks.
d.
Oct 22 '09 #1
4 11296
Markus
6,050 Expert 4TB
I'm stumped on this one. I don't get the same error as you.. I get:

Expand|Select|Wrap|Line Numbers
  1. 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
  2.  
  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
  4.  
  5. Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3
  6.  
  7. 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
  8.  
  9. 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
  10.  
  11. Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3
  12.  
  13. 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
  14.  
  15. Warning: simplexml_load_file() [function.simplexml-load-file]: 0 in C:\xampp\htdocs\index.php on line 3
  16.  
  17. Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\xampp\htdocs\index.php on line 3
Oct 22 '09 #2
Markus,
Thanks for the reply. I've just tried loading the content to a local file via file_get_contents 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.
Oct 22 '09 #3
Markus
6,050 Expert 4TB
@newzdog
I'd tell the site to produce valid XML :D
Oct 22 '09 #4
Have often encountered this problem, this regex should fix the data:

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

It removes all control characters except new lines and carriage returns.
Nov 2 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rainer Mohr | last post by:
Hi, Im having some problems with simplexml_load_file() and cant find any sollution anywhere. Say, we have the following file: ---file.xml--- <UNITS>Metric</UNITS> <UNITS>another</UNITS>...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Harsha | last post by:
Hi All, I am using simplexml_load_file function to parse xml files on my localhost. But the server hosting my domain has php 4.x.x. so i want to use php 4.x.x instead, Is there a way to install...
7
by: alexus | last post by:
i have test.xml file that i pull from someone, and when i try to load it up into php I get this mbp:cj alexus$ php api.php SimpleXMLElement Object ( ) mbp:cj alexus$
7
by: flydev | last post by:
Hi, I am having issues using simplexml. I have generated an XML file using PHP (link), and I am trying to load it into a simplexml object using: $xml =...
1
by: SnakesRule | last post by:
I'm trying to pull data from remote xml files to load the database of a library. My sources are www.amazon.com and www.ISBNdb.com. But when I try to search and read the xml files, I get this error: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.