Click to See Complete Forum and Search --> : getting parsed page source
CrazyMerlin
05-02-2006, 07:10 PM
Posting this in PHP & Javascript forums:
Is there a way to get the contents of a page without loading the page in a browser window, when the page is php?
I know normally this would be fine, but because the page is php, it would need parsing. I need the output once it has been parsed.
If I have to, I can create a window and parse the file, then tear it asunder until I have the content that I need.
Thx!
CM!
NogDog
05-02-2006, 07:26 PM
Try accessing the file via a full URI:
$text = file_get_contents("http://localhost/file.php");
CrazyMerlin
05-02-2006, 09:22 PM
thx NogDog, I was gonna look at that function later this evening.
if not, it's time to learn ajax
CrazyMerlin
05-02-2006, 11:37 PM
No, not working.
I'm using:
$file = urlencode("https://blahblahblah.php?gid=60&un=lemming");
$source = file_get_contents($file);
and I get... failed to open stream: No such file or directory
yet when I put the address into a browser it comes up with the parsed page just fine
if I try it without urlencode, I get: failed to open stream: Invalid argument
any help?
sridhar_423
05-02-2006, 11:55 PM
file_get_contents doesnot work properly in older versions of php.
tht might be the problem.
LiLcRaZyFuZzY
05-03-2006, 12:30 AM
how about if you don't encode the URL?
What version of PHP do you have?
sridhar_423
05-03-2006, 12:45 AM
if you're using some lower versions, replace file_get_contents with the following two lines..
$source=file($file);
$source=implode('',$source);
what i wud suggest is to instead of giving the url, give the path name directly. bcos the way the line gets parsed depends on your server settings.
the reason that its not able to open the stream may be because its searching for the file from your current directory. (though u've given a url..)
NogDog
05-03-2006, 09:27 AM
...
what i wud suggest is to instead of giving the url, give the path name directly. bcos the way the line gets parsed depends on your server settings....
The reason to use the URI is because in this case he wants the result to be processed by the PHP parser.
NogDog
05-03-2006, 09:30 AM
No, not working.
I'm using:
$file = urlencode("https://blahblahblah.php?gid=60&un=lemming");
$source = file_get_contents($file);
and I get... failed to open stream: No such file or directory
yet when I put the address into a browser it comes up with the parsed page just fine
if I try it without urlencode, I get: failed to open stream: Invalid argument
any help?
You need a hostname in the URI. If it's on the same host, just try:
$file = urlencode("https://loalhost/blahblahblah.php?gid=60&un=lemming");
$source = file_get_contents($file);
(If it's not in the root web directory, then add the applicable directory name(s) after the host name.)
CrazyMerlin
05-04-2006, 11:41 AM
Sorry NogDog, I just put blahblahblah instead of the address
The page is not on our server, it is on another server owned by another company.
The parsed page gives a live list, which can change all the time. The company who produce the list do not have an xml file version of the list, and I would like to reproduce that list as a scrolling rss feed.
They have consented to me doing so, but say they cannot help with the gathering of the data (so no db access for me).
The only way I can think to do it is to get the parsed page and tear it apart to get the data I need.
The DOM for the page is always the same as the page is a data-fed template. So I know where to get the data once I get the page contents.
I have done similar things before so I know it works, but I've not done it cross domain before.
I have tried file_get_contents(), fopen() and stream_open(), all with and without urlencode().
Every time I get a stream error, or a file not found error. Although I can paste the address directly into a browser and get the page without incident.
The user id, as you can see, is in the url so it is not that.
I am quite perplexed at this moment and only have 1 other method to fall back on which is very crude. It would involved creating an IFRAME on the fly and setting it's source to the url, waiting a second till it parses, and then accessing contentWindow to get the data from the file.
I know this method would work, and as I could add the IFRAME via DOM and then remove it when done, it could be rather clean. But still, to dynamically create a component like that just seems clumsy, although I may be wrong.
If anybody has any ideas, please let me know.
Thanks guys!
CrazyMerlin
05-04-2006, 12:45 PM
Resolved!
thx go to ultimater!