Forum Moderators: coopster
// Retrieve segment of html from remote resource.
$fd = fopen ("URL", "r");
// Read in current tour page
$buffer = "";
while (!feof ($fd)) {
$current_line = fgets($fd);
$buffer = $buffer . $current_line;
// this line finds the end of the first table in the
// document, we want to return the first table found.
if (strstr($current_line, "</TABLE>")) { break; }
}
fclose ($fd);
// Find beginning of table and do some absolute path rewriting
$current_month = strpos($buffer, "<TABLE WIDTH");
$buffer = substr($buffer, $current_month);
$buffer = str_replace('HREF=', 'href=http://www.myserver.com/phpscripts/getimg.php?', $buffer);
$buffer = str_replace('#FFFFFF"', '#FFFFFF" size=-1', $buffer);
$buffer = str_replace('size="3"', 'size="-1"', $buffer);
$buffer = str_replace('COLOR="#000000"', 'size=-1 COLOR="#000000"', $buffer);
$buffer = str_replace('COLOR="#ff0000"', 'size=-1 COLOR="#ff0000"', $buffer);
$buffer = str_replace('IMG SRC="', 'IMG SRC="http://www.myserver.com/', $buffer);
echo $buffer;
exit(0);
?>
I call this file from another PHP file like this (in the body):
<?php
include 'http://www.myserver.com/fileabove.php';
?>
Something must have gotten pulled into a loop at some point. Either in the while statement or in all those string replaces...you are doing an img src= so maybe when you output that data something weird is going on...
Is the file that's being pulled for the small html snippet dynamically created?
Try using dummy data, and echoing out debugging info every time you perform an operation, on every line in the while statement to check if the file is doing what you expect it to do...
<?php
// Retrieve segment of html from remote resource.
$fd = fopen ("URL", "r");
The code above assumes that the URL exists and is readable. There is no error checking to stop it in the even that the file cannot be opened.
Something along the lines of the code below may help.
$fd= fopen("URL", "r");
if(!$fd) die ("Cannot read URL");
You could also fetch the entire file in one operation again, error handling should be included. My PHP is a bit rusty in this respect as I switched to using TCL for this kind of work a few years ago.
Regards...jmcc
[php.net...]
To check if a file exists using http or ftp use the following:$fp = @fopen("http://www.someurl.com/testfile.php3","r");
if ($fp)
{ print"The file exists!"; }
else
{ print"The file does not exist"; }Note: The "@" in front of fopen suppresses the error output of the function.