[thelist] PHP includes/comparing string values

Timothy Martens timfm at hawaii.rr.com
Mon Mar 4 02:28:00 CST 2002


Hi Evolters! This is my 1st post. I new to PHP and trying to hack out a
script. I'll keep it as short as possible...

 - I have a file that pulls an include into a <textarea> for a user to
edit
 - before pulling the include, I'd like to open it and check it's value
 - if the include's value is exactly equal to the string:
<div style='color: #eee; font: bold 80px Georgia, serif'>Hello
World</div>
...then I want to overwrite that string with $noting (see below); close
the include; and then load it into the <textarea>
 - else (if the include's value is not EXACLTY equal to the above
string), just load it into the <textarea>

This is what I have so far (server is running Linux/Apache/PHP4):

index.php
<?
Header('Cache-Control: no-cache');
Header('Pragma: no-cache');

$noting = "TESTING TESTING 123";
$checkval = "<div style='color: #F00; font: bold 80px Georgia,
serif'>Hello World</div>";
$filename = "thefile.inc";
$fd = fopen($filename, "w");
$contents = fread ($fd, filesize ($filename));

if ($contents == $checkval) {
    fwrite ($fd, $noting);
    fclose ($fd);
    include ($filename);
    } else {
    fclose ($fd);
    include ($filename);
}
clearstatcache();   //do I need this for the next user who edits?
?>

thefile.inc
<div style='color: #F00; font: bold 80px Georgia, serif'>Hello
World</div>

I've set 666 permission on the .inc file and both files live in the same
directory. What seems to be happening when I run index.php is that the
include file gets overwritten with nothing (EVEN IF I CHANGE IT'S VALUE
TO NOT EQUAL $checkval) AND index.php never includes thefile.inc no
matter what. I'm half way to insane here! Thanks for reading.

//t

::::::::::::::::::::::::
<!--Timothy Martens
timfm at hawaii.rr.com-->




More information about the thelist mailing list