PhpDig.net

PhpDig.net (http://www.phpdig.net/forum/index.php)
-   Coding & Tutorials (http://www.phpdig.net/forum/forumdisplay.php?f=31)
-   -   Writing to a file. (PHP) (http://www.phpdig.net/forum/showthread.php?t=820)

Nasimov 04-13-2004 07:15 AM

Writing to a file. (PHP)
 
It's possible to ammend data within a file vs. just adding data to the beginning or the end of the file? Mean to change something in the "middle" of the file.

Thanks.

Charter 04-13-2004 07:38 AM

Hi. Here's one way to do it.
PHP Code:

<?php

$filename 
"filename.ext";
$oldtext "old text";
$newtext "new text";

if (
is_writable($filename)) {
    
$buffer implode(""file($filename));
    
$buffer str_replace($oldtext$newtext$buffer);
    
$handle fopen($filename"wb");
    
fwrite($handle$buffer);
    
fclose($handle);
}
else {
    
clearstatcache();
    echo 
"Cannot write to ".$filename." - Check permissions.";
}

?>



All times are GMT -8. The time now is 01:31 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.