Activity Stream
48,167 MEMBERS
6890 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 4 of 4
  1.     
    #1
    Member

    Default 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 
    Thanks
    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

  2.   Sponsored Links

  3.     
    #2
    Respected 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.

  4.     
    #3
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    I 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

  5.     
    #4
    Member
    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); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replace with Dynamic variable in preg_replace
    By MarPlo in forum Web Development Area
    Replies: 2
    Last Post: 21st Feb 2012, 08:36 AM
  2. Wordpress title preg_replace
    By energyboost in forum Wordpress
    Replies: 2
    Last Post: 3rd Oct 2011, 11:47 PM
  3. Lulzimg preg_replace help
    By masterb56 in forum Web Development Area
    Replies: 2
    Last Post: 15th Aug 2011, 06:31 PM
  4. preg_replace first half of matches ?
    By Porsche_maniak in forum Web Development Area
    Replies: 1
    Last Post: 16th Jan 2011, 05:12 PM

Tags for this Thread

BE SOCIAL