PhpDig.net

Go Back   PhpDig.net > General Forums > Coding & Tutorials

Reply
 
Thread Tools
Old 04-13-2004, 07:15 AM   #1
Nasimov
Green Mole
 
Join Date: Apr 2004
Location: EarthPlanet
Posts: 2
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.
Nasimov is offline   Reply With Quote
Old 04-13-2004, 07:38 AM   #2
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
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.";
}

?>
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
file upload with php piperpowell Troubleshooting 0 05-28-2007 08:48 AM
Writing Arrays to Tables peterl3233 Coding & Tutorials 1 11-10-2005 10:03 PM
including file with php does not work... Fking How-to Forum 5 10-09-2004 10:47 AM
Newbie : How to include PHP file (.php) frostbyte How-to Forum 1 01-04-2004 11:42 AM
How to exclude part of page in a PHP file mario51 How-to Forum 2 12-17-2003 11:13 PM


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


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