TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-11-2009, 11:19 AM   #1 (permalink)
The Wanderer
 
rupam_jaiswal's Avatar
 
Join Date: Jun 2008
Posts: 8
Thanks: 0
rupam_jaiswal is on a distinguished road
Default Edit a file

Hi,
Please excuse if similar query has been posted earlier.

I have text file in which I have to search a word and replace it with a new word.

First I do is to get the file contents with fopen,then read the contents , maintain a string $newcontent that holds the contents of file ,the moment i get my word,replace it with new word in the string $newcontent
After that I write the whole string $newcontent to file again.
What I want is to just while scanning the file,the moment I find my word,replace it with new word there only instead of rewriting the whole file again.
Regards
rupam_jaiswal is offline  
Reply With Quote
Old 06-11-2009, 08:36 PM   #2 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

I don't know if there is a way with a file but don't quote me on this as I'm still quite knew myself however what you can do which i would recommend is create a .php file that will connect to a mysql database and then use the php file to create the .txt and then simply store your newcontent within a mysql database.

Basically to do that without having to enter then click a link to visit the php page you can take your form (im assuming your using a form to get your newcontent) and make it get processed in the .php page then make the php page update the mysql database, then read the database and output a .txt page and after it outputs the .txt page make it redirect to the .txt

Sorry if i did not answer your question, I will see if i can come up with anything.

Cheers,
Randy
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-12-2009, 04:05 AM   #3 (permalink)
The Contributor
 
jcorradino's Avatar
 
Join Date: Sep 2008
Posts: 36
Thanks: 2
jcorradino is on a distinguished road
Default

I know for sure that the easiest ways are to either rewrite the file or concatenate the information into the file. I would assume that what you are looking for is possible, I would just need to research the answer a little but more though.

My guess would be by opening the file, reading its contents, noting where the change(s) need to be, positioning the pointer, and then editing the data. Possible, most likely... pain in the ass, absolutely.
__________________
Jason Corradino
Applications Developer, Interactive Support - Tribune Technology
J2EE Development, Script Tinkering - Develop, Support, and Maintain Tribune websites.
jcorradino is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy to Modify Login Script with Hierarchical User Permissions and XML Account File Wildhoney Script Giveaway 4 05-04-2011 06:11 AM
Where is my file? superthin General 3 07-25-2009 09:48 AM
Back to Basics: File uploading delayedinsanity Absolute Beginners 12 10-03-2008 10:14 AM
Aptana Jaxer and file uploads xenon Advanced PHP Programming 2 06-06-2008 10:22 AM
Writing to XML file buildakicker General 8 02-06-2008 08:17 PM


All times are GMT. The time now is 04:35 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design