Forum Moderators: coopster

Message Too Old, No Replies

Help including external file

no I'm not scraping

         

too much information

5:09 am on Apr 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have two sites that I am trying to get to "talk" to each other.

I have one site that contains a PHP file that basically outputs an XML formatted list depending on the file structure in that directory.

The other site needs this XML formatted data to complete the PHP generated XML file that I am trying to put together. (Much like syndicating my content from one site to another)

I have tried using readfile, include and header(Location:) and none of them seem to be working. What I need is for the calling file to somehow include the output of the remote file. (The same stuff you see if you view the source) What happens is that I can 'readfile' my index page on that site, but not the one that puts out the XML data that I need. Could it be that the XML file doesn't actually create any visual content on the page? or doesn't have 'head' and 'body' tags?

It would be great if I could do all of this in PHP so that the final source would not include anything that would disrupt the final XML output.

Does anyone have any suggestions?

ironik

5:21 am on Apr 29, 2005 (gmt 0)

10+ Year Member



Most browsers will be able to render XML into something visual, even if it doesn't have the standard html tags.

Is your XML file being generated by a php file and stored statically? e.g. xml.php outputs a file something.xml? If it isn't I'd probably write it so that is is output statically and then use the function file_get_contents() on the URL to the file.

If it's being generated dynamically each time, I think some of the functions will just read the php file without the parser running over it, which would be useless. I'm not sure how, if at all, you can read the dynamically generated contents of a php file unless you pass the output as a variable.

too much information

9:45 pm on Apr 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not against passing the content as a variable, but is it possible to call a PHP page on another server and have it return a variable to a PHP script on my server?

Is that alot like using return() in Javascript?

coopster

12:50 am on May 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Did you try the file_get_contents() [php.net] function as suggested? Works perfect for returning the "source" of a file into a string variable...

too much information

12:10 pm on May 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops... I didn't catch that in the other reply.

Thanks Coopster! I'll give that a try.

too much information

1:40 am on May 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I gave that a try and it looks like I'm getting close. Here's the error I get:

Warning: file_get_contents(http://www.domain.com/directory/file.php): failed to open stream: HTTP request failed! HTTP/1.1 404 in d:\other_domain\html\test\other_file.php on line 16

(If I call the file.php in my browser it works fine.)

Line 16 looks like this:

$xml_data = file_get_contents($xml_file);

if I "urlencode($xml_file)" I get an error that the file does not exist.

Could this be something in my php.ini file on the domain I'm trying to get the file contents from? Or could it be that the file I'm trying to read does not have <head> or <body> tags?

Stormfx

3:39 am on May 4, 2005 (gmt 0)

10+ Year Member




Well, if you're using Windows, it has issues with reading remote files. You could try using the XML functions that come with PHP:

[php.net...]

HTH