RE: [PHP-WIN] Writing to a file
| From: | Gerardo Rojas | Date: | Fri, 26 Sep 2003 19:59:16 +0000 |
| Subject: | RE: [PHP-WIN] Writing to a file | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-21575@lists.php.net to get a copy of this message | ||
MG29,
this doesn't work. It will still write the new line after the line (I matched). Everytime I
read a line from a file, the $fd gets incremented, so when I say fwrite, $fd is already pointing to
the next line in the file? Any suggestions as to working around this? I can't rewrite the
entire file (design time controls on page, they wouldn't work if I did). As soon as I fix the
Cascading Style Sheet line, I want to get out of the file.
-----Original Message-----
From: GaguWD [mailto:larenga2985@yahoo.com.ar]
Sent: Thursday, September 25, 2003 6:17 PM
To: Gerardo Rojas
Subject: RE: [PHP-WIN] Writing to a file
You should use regex (regular expressions) to do this, because is simpler.
You can get the contents of the files into a variable:
<?
$file = "any_file.txt";
$op = fopen($file,"w+");
if($op) {
while(!feof($op)) {
$read .= fread($op,1024);
}
}
if(preg_replace("/something i don't want/i",$sthiwant,$read)) {
echo "It's done!";
} else {
echo "Something didn't work, complain to the person who gave you this code
;-)";
}
?>
Hope it helps!
Byes!
MG29
-----Mensaje original-----
De: Gerardo Rojas [mailto:grojas@strategicinc.com]
Enviado el: Jueves, 25 de Septiembre de 2003 03:09 p.m.
Para: php-windows@lists.php.net
Asunto: [PHP-WIN] Writing to a file
I'm am able to open the file read and write to it. The problem is that I
want to replace a line of text with another line. My function is actually
writing my new line after the line I wanted to change. Can we do arithmetic
on the $fd (file handle or file descriptor)? To tell PHP to write where (
$fd - 1 ) points to?
--
Gerardo S. Rojas
mailto: grojas@strategicinc.com