RE: [PHP] Simple Text Files Functions...

From: Date: Wed, 21 May 2003 10:05:48 +0000
Subject: RE: [PHP] Simple Text Files Functions...
Groups: php.general 
Request: Send a blank email to php-general+get-148391@lists.php.net to get a copy of this message
> -----Original Message----- > From: Russell P Jones [mailto:rjones@email.unc.edu] > Sent: 21 May 2003 00:13 > To: php-general@lists.php.net > Subject: [PHP] Simple Text Files Functions... > > > 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)); } Have you tried displaying what's in $text at this point? I'm only guessing (aka I'm too lazy to try it out!), but I wouldn't be surprised to learn that it's empty. (If you find it is, let us know and I'll explain my reasoning!) > > 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? Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#148391) next »