[thelist] PHP includes/comparing string values
Andrew Forsberg
andrew at thepander.co.nz
Mon Mar 4 19:06:01 CST 2002
At 3:01 PM -1000 4/3/02, Timothy Martens wrote:
>So it sort of works. I mean when the $contetns == $checkval -- it does
>overwrite the $filename with return $noting/"TESTING"
>
>BUT... When I refresh/comeback to the page. That is, when $contents and
>$checkval are no longer equal, rather than just including $noting, it
>seems to be overwriting "thefile.inc" altogether with NOTHING?
Hi Tim,
Try not opening the "w" connection until you have to. Opening it with
"w" will erase everything in the file -- as you've seen :-). In
pseudo code you want to:
open the file (read only)
read the file contents into a string
close the (read only) file
compare the contents string and your check value
if they're equal
- open a write connection
- write the value
- close the connection
- include the file
else, if they're not equal
- include the file
So, you do your read stuff first, then, if you need to overwrite the
file you open a "w" connection, otherwise you don't need to fopen() a
write connection at all.
HTH
Andrew
--
More information about the thelist
mailing list