Simple Text Files Functions...
| From: | Russell P Jones | Date: | Tue, 20 May 2003 23:12:47 +0000 |
| Subject: | Simple Text Files Functions... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-148336@lists.php.net to get a copy of this message | ||
Ok so Im a newbie, but I really need some help with this...
All I am trying to do is open a file of just text, replace 5 characters
that appear once in the document with a string of text that has the
variable named $string.
Here was my best try...
<?
$substring = 'my new substring';
$fp = fopen($filename, "r") or die("sorry folks");
while (!feof($fp)){ $text = fread($fp, filesize($fp)); }
fclose($fp);
$fp2 = fopen($filename, "w") or die("sorry folks again");
$string = preg_replace('/(</stories>)$/', $subsrting, $text);
$bytes = fwrite($fp2, $string);
fclose($fp2);
echo $bytes;
?>
Couple of questions...
(1) Why is this not working :)
(2) Do i need to do something special since the characters I am searching
for includes a <, /, and > ?
(3) Why am I hopeless?
Russ