1

I'm trying to read the contents of an external xml feed. When I view the link in the browser it renders the xml contents as it should, but when I run it in my browser I get errors. My code is as follows:

<?php
$url = "http://www.thebigchoice.com/feeds/job_xml.php";

$xml = simplexml_load_file($url); 

print_r($xml);
?>

Here is the error that I'm getting:

( ! ) Warning: simplexml_load_file() [function.simplexml-load-file]: http://www.thebigchoice.com/feeds/job_xml.php:1: parser error : Start tag expected, '<' not found in C:\wamp2\www\phpAcademy\TheBigChoice\TMPr785mziagz.php on line 14
Call Stack
#   Time    Memory  Function    Location
1   0.0004  365880  {main}( )   ..\TMPr785mziagz.php:0
2   0.0004  366048  simplexml_load_file ( ) ..\TMPr785mziagz.php:14

( ! ) Warning: simplexml_load_file() [function.simplexml-load-file]: Unknown type: [8] Undefined index: HTTP_USER_AGENT<br /> in C:\wamp2\www\phpAcademy\TheBigChoice\TMPr785mziagz.php on line 14
Call Stack
#   Time    Memory  Function    Location
1   0.0004  365880  {main}( )   ..\TMPr785mziagz.php:0
2   0.0004  366048  simplexml_load_file ( ) ..\TMPr785mziagz.php:14

( ! ) Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\wamp2\www\phpAcademy\TheBigChoice\TMPr785mziagz.php on line 14
Call Stack
#   Time    Memory  Function    Location
1   0.0004  365880  {main}( )   ..\TMPr785mziagz.php:0
2   0.0004  366048  simplexml_load_file ( )
user615099
  • 115
  • 2
  • 12

1 Answers1

1

The output of the URL is

Unknown type: [8] Undefined index:  HTTP_USER_AGENT<br />
Line : 20  File :/var/www/thebigchoice/html/includes/Common/setup.php<br /><br />WARNING: [2] Cannot modify header information - headers already sent by (output started at /var/www/thebigchoice/html/includes/Common/functions.php:80)<br />
Line : 10  File :/var/www/thebigchoice/html/includes/Common/feeds/feeds_complete_job_feed_minus_247.php<br /><br /><?xml version="1.0" encoding="utf-8"?>
<XMLJobFeed><Job><CompanyRef>60</CompanyRef><JobTitle>Enterprise Management Training Programme</JobTitle><SummaryLocation>Worldwide</SummaryLocation><SalaryBenefits>Competative</SalaryBenefits><Summary>SWYgeW91IHNlZSB5b3Vyc2VsZiBhcyBvbmU

So apparently, the script checks for the User Agent in the HTTP Request, cannot find it and then outputs errors before it sends the actual XML. It's apparently a poorly written script.

The solution is to set the UserAgent. You can do that globally in your php.ini or with a stream context. See my answer to How can I download using PHP a XML file redirected in some weird way? on how to achieve that.

Community
  • 1
  • 1
Gordon
  • 312,688
  • 75
  • 539
  • 559