By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 940 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

problem to open a distant XML file in PHP

P: n/a
Hi,

I try to open a distant (not local) XML file in PHP to read an RSS feed.

I can open an HTML page and read it with the file() function.

But as soon as I try with a RSS feed instead of HTML and I try to read
or open with file() or fopen(), it doesn't work, I have the following
errors :

Warning: fopen() [function.fopen]: php_hostconnect: connect failed in
D:\test.php on line 10

Warning: fopen(http://www.clubic.com/xml/news.xml) [function.fopen]:
failed to create stream: Bad file descriptor in D:\test.php on line 10

In my phpinfo, the parameters are like this :
PHP Version 4.3.1
Registered PHP Streams php, http, ftp, compress.zlib
allow_url_fopen On On
XML Support active
XML Namespace Support active
EXPAT Version 1.95.2

My source file is :
<?php
$fichier_xml = "http://www.clubic.com/xml/news.xml";
$file = fopen($fichier_xml,"r");
?>

Could someone help me ?

Thanks.

(Sorry for my "frenchynglish")
Feb 13 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Feb 13, 11:35 am, Claire DURAND <claidur...@NOSPAMyahoo.frwrote:
Hi,

I try to open a distant (not local) XML file in PHP to read an RSS feed.

I can open an HTML page and read it with the file() function.

But as soon as I try with a RSS feed instead of HTML and I try to read
or open with file() or fopen(), it doesn't work, I have the following
errors :

Warning: fopen() [function.fopen]: php_hostconnect: connect failed in
D:\test.php on line 10

Warning: fopen(http://www.clubic.com/xml/news.xml) [function.fopen]:
failed to create stream: Bad file descriptor in D:\test.php on line 10

In my phpinfo, the parameters are like this :
PHP Version 4.3.1
Registered PHP Streams php, http, ftp, compress.zlib
allow_url_fopen On On
XML Support active
XML Namespace Support active
EXPAT Version 1.95.2

My source file is :
<?php
$fichier_xml = "http://www.clubic.com/xml/news.xml";
$file = fopen($fichier_xml,"r");
?>

Could someone help me ?

Thanks.

(Sorry for my "frenchynglish")
You can't use fopen() on remote files. Try this instead:
$file = implode( '', file( $$fichier_xml ) );

That will put the entire rss feed into the $file variable for you to
parse or whatever

Feb 15 '07 #2

P: n/a
On Feb 13, 11:35 am, Claire DURAND <claidur...@NOSPAMyahoo.frwrote:
Hi,

I try to open a distant (not local) XML file in PHP to read an RSS feed.

I can open an HTML page and read it with the file() function.

But as soon as I try with a RSS feed instead of HTML and I try to read
or open with file() or fopen(), it doesn't work, I have the following
errors :

Warning: fopen() [function.fopen]: php_hostconnect: connect failed in
D:\test.php on line 10

Warning: fopen(http://www.clubic.com/xml/news.xml) [function.fopen]:
failed to create stream: Bad file descriptor in D:\test.php on line 10

In my phpinfo, the parameters are like this :
PHP Version 4.3.1
Registered PHP Streams php, http, ftp, compress.zlib
allow_url_fopen On On
XML Support active
XML Namespace Support active
EXPAT Version 1.95.2

My source file is :
<?php
$fichier_xml = "http://www.clubic.com/xml/news.xml";
$file = fopen($fichier_xml,"r");
?>

Could someone help me ?

Thanks.

(Sorry for my "frenchynglish")

Try this:

$file = implode( '', file( $fichier_xml ) );

Instead for that last line, it will just put the entire feed into the
$file variable. I'm just guessing, I don't know if that will solve
your problem for sure.

Feb 15 '07 #3

P: n/a
VS
sumguyovrthar wrote:
You can't use fopen() on remote files. Try this instead:
$file = implode( '', file( $$fichier_xml ) );
Rubbish !

(PHP 4, PHP 5)
fopen Opens file or URL

This works for me:

$URL = "http://wwe.......";

if (!($remotefile = @ fopen("$URL", "r"))) {
//echo "Error: url could not be opened<br />\n";
die();
}

--
VS
Feb 16 '07 #4

P: n/a
Rik
On Fri, 16 Feb 2007 19:36:16 +0100, VS <vs@nospam.blueyonder.invalid
wrote:
sumguyovrthar wrote:
>You can't use fopen() on remote files. Try this instead:
$file = implode( '', file( $$fichier_xml ) );

Rubbish !
Well, sort of, it depends on allow_url_fopen, which is usually enabled.
--
Rik Wasmus
Feb 16 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.