Re: [PHP3] ereg_replace
| From: | Zak Greant | Date: | Tue, 20 Jun 2000 19:07:12 +0000 |
| Subject: | Re: [PHP3] ereg_replace | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2339@lists.php.net to get a copy of this message | ||
Hello Travis,
I have taken the liberty of modifying your code a little bit - I should have looked more closely at it when I answered the first time :)
<?php
# Define variables
$file = 'file.txt';
$floorvar = 'floor';
$long_floorvar = 'long_floor';
# Open file and read into variable
$fd = fopen ($file,'r');
$contents .= fread ($fd, filesize ($file));
fclose ($fd);
/* Modify regular expressions so that they only replace complete words */
$contents = ereg_replace
(
'([^[:alpha:]])LONG_FLOORVAR([^[:alpha:]])',
"\\1$long_floorvar\\2",
$contents
);
$contents = ereg_replace
(
'([^[:alpha:]])FLOORVAR([^[:alpha:]])',
"\\1$floorvar\\2",
$contents
);
# Write data to file.
# I have split reading the data and writing the data
# so that if the content is shorter in the data that
# is written back to the file, there will not be
# extra characters from the old file left at the end
# of the file.
$fd = fopen ($file,'w');
fwrite ($fd, $contents);
fclose ($fd);
?>
# file.txt
<?php
$floor = "FLOORVAR";
$long_floor = "LONG_FLOORVAR";
?>
Good Luck,
Zak
At 06:10 PM 6/20/00 +0000, Travis Ruthenburg wrote:
While I definately appreciate you pointing out my gross oversight, it does not appear to change anything.HTH, Zak Greant "I am rather like a mosquito in a nudist camp: I know what I ought to do, but I don't know where to begin." - Stephen Baynethe script: <?php include "admin_header.inc";It looks like tou need to assign the result of ereg_replace back into $contents.$floorvar = "floor"; $long_floorvar = "long_floor";$fd = fopen ("/usr/local/www/forums/skel/floor/index.phtml","r+");$contents = fread ($fd, filesize("/usr/local/www/forums/skel/floor/index.phtml"));print $contents;ereg_replace("FLOORVAR", $floorvar, $contents); ereg_replace("LONG_FLOORVAR", $long_floorvar, $contents);fclose($fd);print $contents;include "admin_footer.inc"; ?> The file: <?php include "header.inc"; $floor = "ROOMVAR"; $long_floor = "LONG_FLOORVAR"; include "footer.inc"; ?>