Re: Simple Text Files Functions...
| From: | Burhan Khalid | Date: | Tue, 20 May 2003 23:18:39 +0000 |
| Subject: | Re: Simple Text Files Functions... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148339@lists.php.net to get a copy of this message | ||
Hello Russell,
Tuesday, May 20, 2003, 6:12:47 PM, you wrote:
RPJ> Ok so Im a newbie, but I really need some help with this...
RPJ> All I am trying to do is open a file of just text, replace 5 characters
RPJ> that appear once in the document with a string of text that has the
RPJ> variable named $string.
RPJ> Here was my best try...
RPJ> <?
RPJ> $substring = 'my new substring';
RPJ> $fp = fopen($filename, "r") or die("sorry folks");
If you are using PHP version 4.3+, you can use file_get_contents :
$text = file_get_contents($filename);
RPJ> while (!feof($fp)){ $text = fread($fp, filesize($fp)); }
RPJ> fclose($fp);
RPJ> $fp2 = fopen($filename, "w") or die("sorry folks again");
RPJ> $string = preg_replace('/(</stories>)$/', $subsrting, $text);
$subsrting should be $substring
error_reporting(E_ALL); would have pointed that out
RPJ> $bytes = fwrite($fp2, $string);
try fputs()
RPJ> fclose($fp2);
RPJ> echo $bytes;
?>>
--
Best regards,
Burhan mailto:phplist@meidomus.com