Current location: Hot Scripts Forums » Programming Languages » PHP » replacing certain parts of certain strings in text files


replacing certain parts of certain strings in text files

Reply
  #1 (permalink)  
Old 07-29-03, 05:23 PM
Archbob Archbob is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
replacing certain parts of certain strings in text files

Lets say I have a large text file and I have a certain string like
Quote:
block save guard defend
And I want to find this string in the text file(the actual string I'm referring to goes on two lines) and then I want to replace say save with !save if a condition is true but only within this string in the file. There are other places within the file that have 'save' but I don't want to touch them. After replacing save with !save in that string, I want to write the new file over the old file. So how do I do this. Every time I've tried, it replaces every instance of save with !save in the file and not just the instances within the string which is what I want.

Basically I'm asking how to use the limit parameter in preg_replace to replace the last instance of "save" with "!save" , since there are about 6 instances on the page.
__________________
Master Chipmunk and programmer of cheap scripts.
Chipmunk Scripts -- Free GPL scripts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying all duplicate records in my table. dsumpter PHP 6 09-02-03 11:54 AM


All times are GMT -5. The time now is 01:48 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.