#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    39
    Rep Power
    17

    Quick regex wildcard question.


    Sorry if this is a dumb question, just got the bug to start php programming again and lost all my old scripts.

    Can some one give me the str_replace syntax to match and replace the following instances - they just need to be replaced by "" and the number could reach double figures.

    aR[0]
    aR[1]
    aR[2]

    Thanks
  2. #2
  3. AZbb founder
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    London, UK
    Posts
    843
    Rep Power
    14
    str_replace does not take RegEx.

    Here is a simple one:

    Code:
    <?php
    
    $test = " aR[0] aR[1] aR[2]";
    $test = preg_replace("/\[\d+\]/i","[]",$test);
    echo $test;
    
    ## prints
    # aR[] aR[] aR[]
    
    ?>
    Good luck
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    39
    Rep Power
    17
    Thanks for your help

    got it working

    $code = preg_replace("/aR\[\d+\]/i","",$code);

    Think I really need to spend some time with the manual to sort out the regex stuff so I can actually unfderstand what all the /'s etc refer to .

IMN logo majestic logo threadwatch logo seochat tools logo