View Full Version : please help! tricky file generation problem

02-11-2003, 01:23 PM

I have a problem with a HTML generator script I am writing. Basically, I run a PHP script in a while loop. The output of this is stored in a file and then using PHP's file functions, this file is written into a HTML file.

The code in my PHP file is fine but there is a problem with the generated HTML.
Firstly, I am passing a value and using ereg_replace to replace the word -track- in the PHP file with this value. This value is a word and it can be of variable length. Now, when say I run through a loop of 10 names, each of different lengths. When I open the generated HTML files I am seeing parse errors that aren't actually correct.

ie - This error is coded into the generated HTML page because it occurred when the PHP script was being run:

Fatal error: Call to undefined function: ifx_fet() in
c:\program files\nusphere\apache\nsdocs\horseracingresults\rebuild\resultscache.php on line 104

Obviously, ifx_fet() isnt a function. The actual line 104 code in resultscache.php is this:

while($row1 = ifx_fetch_row($result1)){

This is an informix DB function and when I run resultscache.php in the browser and not through the generator script, there are no parse errors. Similarly, in one of the other generated HTML files there is this error:

Fatal error: Call to undefined function: ifx_fetch_row_row()

in c:\program files\nusphere\apache\nsdocs\horseracingresults\rebuild\resultscache.php on line 104

The word that was passed to generate the first file was 13 characters long while the word for the 2nd file was 7 characters long. For some reason, the PHP seems to be getting messed up when it is read into my script.

I use the code below to read a txt file, replace the appropriate words, save it as resultscache.php, run resultscache.php and then save the HTML output of resultscache.php as a HTML file:

$tempfilename = "tempindex.html";
$targetfilename =

//put space back in track for DB query
$track = ereg_replace("_", " ", $track);
<title>Generating HTML...</title>
<p>Generating <?= $targetfilename?>...</p>

//change the txt file into a PHP file that replaces placeholder text
with the correct PHP generated Track name (generated from the
$tempfile = "resultscache.php";
$fp1 = fopen($tempfile, 'w');
$fp = fopen($filepath."resultscache.txt", "w") or die("Couldn't open file");
$data = fread($fp, filesize($fp));
$data .= fread($fp, 100000);
$toreplace = "-track-";
$replacewith = $track;
$data = ereg_replace($toreplace, $replacewith, $data);
$toreplace1 = "-date-";
$replacewith1 = $startdate;
$data = ereg_replace($toreplace1, $replacewith1, $data);
$ok = fwrite($fp1, $data);
//generate php file end


$dynpage = fopen($srcurl, 'r');

echo("<p>Unable to load $srcurl. Static page "."update aborted!</p>");

$htmldata = fread($dynpage, 1024*1024);


$tempfile = fopen($tempfilename, 'w');

echo ("<p>Unable to open temporary file");

fwrite($tempfile, $htmldata);

$ok = copy($tempfilename, $targetfilename);


I am stumped with this and I have a dealdine hanging ove rmy head so any help is appreciated!


note: there is forward slashes in the rror output but vBulletin removes them.