Results 1 to 4 of 4
-
24th Sep 2012, 11:08 AM #1OPMember
Preg_replace help
Im scanning 1000's of files and want to replace certain values to 0
The values here 750,15 need to be changed to 0 and pushshort changed to pushbyte.
pushshort could be between 1-10,000
time could be between 1-10,000
The whole code needs to be matched so it doesnt edit the wrong sections in files.
PHP Code:pushstring "costs"
pushstring "r1"
pushshort 750
pushstring "r2"
pushbyte 0
pushstring "r3"
pushbyte 0
pushstring "r4"
pushbyte 0
pushstring "time"
pushbyte 15
And any number in this set to 0, and pushshort changed to pushbyte.
PHP Code:pushstring "repairTime"
pushbyte 30
pushbyte 60
pushbyte 120
pushshort 240
pushshort 480
pushshort 960
pushshort 1920
pushshort 3840
pushshort 7680
pushshort 15360
Gavo Reviewed by Gavo on . Preg_replace help Im scanning 1000's of files and want to replace certain values to 0 The values here 750,15 need to be changed to 0 and pushshort changed to pushbyte. pushshort could be between 1-10,000 time could be between 1-10,000 The whole code needs to be matched so it doesnt edit the wrong sections in files. Rating: 5
-
25th Sep 2012, 01:59 PM #2Respected Member
Are these files layed out as one line for each variable/value? Are the files separate meaning that the first line with pushstring "costs" or pushstring "repairTime" would never be in same file?
If the answers are yes than I would read the folders and files as sequential data and either create new files or rewrite the lines updating the line based on your criteria and what is in the first line.
-
25th Sep 2012, 06:27 PM #3The Wise OneWebsite's:
twilight.ws ddlrank.comI think you are better of running PHP's exec command since PHP isn't really designed to manipulate files (eg find and replace):
PHP Code:exec('perl -w -i -p -e "s/search_text/replace_text/g" foldercontainintallfiles');
I can always be contacted by sending a tweet @twilightws
-
25th Sep 2012, 07:23 PM #4OPMember
I done it, it was easier than i thought
PHP Code:$result1 = preg_replace('/([a-z]{10}\s*"[a-z1-4]{1,4}"\s*\n*[a-z]{1,15}\s*[0-9]{1,10}\n*\s*){5}/',
'pushstring "r1"
pushbyte 0
pushstring "r2"
pushbyte 0
pushstring "r3"
pushbyte 0
pushstring "r4"
pushbyte 0
pushstring "time"
pushbyte 0 ', $text);
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Replace with Dynamic variable in preg_replace
By MarPlo in forum Web Development AreaReplies: 2Last Post: 21st Feb 2012, 08:36 AM -
Wordpress title preg_replace
By energyboost in forum WordpressReplies: 2Last Post: 3rd Oct 2011, 11:47 PM -
Lulzimg preg_replace help
By masterb56 in forum Web Development AreaReplies: 2Last Post: 15th Aug 2011, 06:31 PM -
preg_replace first half of matches ?
By Porsche_maniak in forum Web Development AreaReplies: 1Last Post: 16th Jan 2011, 05:12 PM
themaCreator - create posts from...
Version 3.24 released. Open older version (or...