php xml file doesnt display (simplexml_load_file)

javiermorquecho
javiermorquecho used Ask the Experts™
on
Hi EE!

I try to read a doubleclick.com process that give a XML response. The problem, in development read the XML and shows me the info, but in production doesnt. I added a file_exist function and show me "no exist"

I attach the code.

Thnx a lot
$ord=rand(1000,100000);
$file = 'http://ad.doubleclick.net/adx/xxx/xxx;dcmt=text/xml;sz=###x###;ord='.$ord;

if (file_exists($file)) {
	echo "exist";
}else{
	echo "no exist";
}

$ads = simplexml_load_file($file);
$small_img = $ads->small_img;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The file simply doesn't exist!
Top Expert 2004
Commented:
You cannot use file_exists() to check the existence of a remote HTTP file. It simply doesn't work and is not supported. The documentation on SimpleXML is vague, but it is potentially possible that your online server has stricter security settings that prevent this from happening (just a guess!). Does fopen() or file_get_contents() or include() work with URLs? What version of PHP are you using?

If the remote file actually exists, and persists in being difficult to load directly, you may be able to grab the file and load it as a string, i.e. http://www.php.net/manual/en/function.simplexml-load-file.php#97077.

Author

Commented:
The file exist. I can see it in the browser. Is in a XML format. Maybe the simplexml_load_file function, doesn't find it becouse is a proccess slowly ( 0_0 ).  I try with domdocument, fopen(), file_get_contents() and curl().
I use PHP 5.2. I review the PHP libraries and all it's OK (enabled).
With file_get_contents() and curl() gives me a HTML code with other information 0_0.
I will to try the link in the monday the link.

Thnx!
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Top Expert 2004

Commented:
It should be an XML file, right? Not an HTML file with other assorted information. Look in server logs to see if any errors are being logged.
Most Valuable Expert 2011
Top Expert 2016
Commented:
I looked at this URL:
http://ad.doubleclick.net/adx/xxx/xxx;dcmt=text/xml;sz=###x###;ord=1234

It returned this string:
<html><body></body></html>

So if you're seeing something in the browser window that looks like XML, you might want to post the actual URL of that page here so we can see what you are looking at.  Also, the SimpleXML functions return certain kinds of values, so where you have code like this:

$ads = simplexml_load_file($file);

You might want to use var_dump($ads) to visualize the information.

Author

Commented:
Hi Experts!

Zyloch: It´s a XML. Looks like XML in the browser. I will to check the server logs.

Ray_Paseur: It´s a XML if I open in the browser. When I try to open with curl or get_file_contents I see HTML tags with wrong info, in HTML.

Thnx
Most Valuable Expert 2011
Top Expert 2016

Commented:
It´s a XML if I open in the browser.

What is the URL that you open in the browser to see XML?
Most Valuable Expert 2011
Top Expert 2016

Commented:
When I visit that URL, I get redirected to a URL that has an XML parsing error.  Are you using CURL to read the thinurl.info page?

Author

Commented:
I put a url redirect, becouse is important for me the privacity. I'm using the PHP fucntions with the final url.

How do you detect the parsing error?.

I'm reading the XML with differents ways to try. Ultimately the simplest form, simplexml_load_string, and simplexml_load_file.

In the code: shows me a error int eh line 42 ($ads = simplexml_load_file( $filename3 );). The error is:

Warning: simplexml_load_file() [function.simplexml-load-file]: http://ad.doubleclick.net/adx/xxx/xxx;dcmt=text/xml;sz=320x44;ord=000: parser error : EntityRef: expecting ';'

and parser errors like : Premature end of data in tag a line in a few lines

Thnx a lot!

$ord=rand(1000,100000);
$filename3 = 'http://ad.doubleclick.net/adx/es.esmas.dep_movil_iphone/minutoaminuto;dcmt=text/xml;sz=320x44;ord=' . $ord;

$ads = simplexml_load_file( $filename3 );
echo "simplexml_load_file 3<pre>";
print_r( $ads );
echo "</pre>";

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial