Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    var
    var is offline
    New Coder
    Join Date
    Mar 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with preg_replace...

    Hi,

    I'm having trouble with preg_replace...
    basically i wanted to use str_replace but needed to limit the replacement to 1 so had to resort to preg_replace.

    problem is i cant get the thing to work..

    PHP Code:
    for ($i=0$i<4$i++) {
      
    $str preg_replace(${'old_'.$i}, ${'new_'.$i}, $str1);

    the problem i get is that as soon as the replace occurs, it makes $str empty instead of just replacing what its supposed to.

    it all works fine with str_replace but like i said, i needed to limit the replace to 1.

    thanks.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Since you are now using preg_replace(), are the values in ${'old_'.$i} formatted as regular expressions?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •