473,398 Members | 2,188 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,398 software developers and data experts.

problem to open a distant XML file in PHP

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
4 3266
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Michael Foord | last post by:
I'd like to formalise slightly the license I release my projects under. At the moment it's 'free to use, modify, distribute and relicense'. This is basically fine as I don't want t oprevent people...
4
by: puzzlecracker | last post by:
I have encountered certain confusion while scrutinizing the long distance friendship engendering violation of encapsulation. If object (be it a class, variable, function, etc) has an internal...
3
by: MLH | last post by:
I seem to remember a post in the distant past discussing how to switch to another open application window. IE, if WordPad is running, some API function that'll allow me to switch the focus to that...
11
by: John Baker | last post by:
Hi: I have a table which is indexed on an auto number (supposedly unique for each record). For reasons I cannot explain, I have started to encounter a problem with duplicate auto numbers. The...
5
by: Eric Twietmeyer | last post by:
Hi, Does anyone know why starting with VS.NET 2002 (and same with 2003) it is no longer possible to browse to a directory that has "ept" as part of the path? It worked fine in Vc 6.x. My...
2
by: Steve Chatham | last post by:
I use the following code: Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged Dim sFile As String =...
1
by: Łukasz | last post by:
Good Evening, I have a problem with configuration PHP on server linux which is connected with distant server pervasive 8.5(novell). Connection odbc work without problems isql myDSN , Connected!...
1
by: Nicolas | last post by:
Hello, On a Windows platform (XP SP2), using Wampserver 2.0, each time I try to access a distant file with PHP: $contents =...
4
by: pavanip | last post by:
Hi , I have a problem with importing database from local system to web hosting server. can you Please tell me the steps to import database from local machine to web hosting server.I am using Sql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.