Hi,

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:
PHP Code:
Fatal errorCall to undefined function: ifx_fet() in 
c
:program filesnusphereapachensdocshorseracingresultsrebuildresultscache.php on line 104 
Obviously, ifx_fet() isnt a function. The actual line 104 code in resultscache.php is this:
PHP Code:
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:
PHP Code:
Fatal errorCall to undefined function: ifx_fetch_row_row()

 
in c:program filesnusphereapachensdocshorseracingresultsrebuildresultscache.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:

PHP Code:
$tempfilename = "tempindex.html";
$targetfilename = 
"html/".$startyear."/".$startmonth."/".$startday."/".$track.$startdate.".html";

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

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

//unlink($tempfilename);

$dynpage fopen($srcurl'r');

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

$htmldata fread($dynpage1024*1024);

fclose($dynpage);

$tempfile fopen($tempfilename'w');

if(!
$tempfile){
    echo (
"<p>Unable to open temporary file");
    exit();
}

fwrite($tempfile$htmldata);

fclose($tempfile);
$ok copy($tempfilename$targetfilename);

unlink($tempfilename);
I am stumped with this and I have a dealdine hanging ove rmy head so any help is appreciated!

Thanks,
Martin

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