Problem using simplexml_load_file to access service

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Problem using simplexml_load_file to access service

Postby sn_pst » 02. December 2010 16:25

Hi,

I'm learning PHP and trying to learn how to call a service .
I try to use the simplexml_load_file but it doesn't work (it always returns false -- code below). I did some research and found that allow_url_fopen in php.ini should be "on" but it doesn't solve the problem.

Code: Select all
$xml = simplexml_load_file('http://finance.yahoo.com/rss/headline?s=lvs'); 
 
if ( $xml == false ) 
echo "something wrong when parsing xml."; 


I do testing in my local windows Vista machine using XAMPP.
Thanks in advance for the help.
sn_pst
 
Posts: 1
Joined: 02. December 2010 16:06

Re: Problem using simplexml_load_file to access service

Postby Altrea » 02. December 2010 18:24

sn_pst wrote:
Code: Select all
if ( $xml == false )


I do testing in my local windows Vista machine using XAMPP.
Thanks in advance for the help.


If you want to check against boolean values (TRUE or FALSE), the Integers 0 or 1 or the strings "0" or "1" you should always use === instead of ==. Otherwise the php interpreter tries to check if any of the check values match.
It helps too to check for the variable type or in your case to check if is_object($xml), because simplexml_load_file returns an object on success
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 31 guests