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
    New Coder
    Join Date
    Jul 2007
    Location
    Latin America
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with preg_replace...

    Code:
    $line = preg_replace("'\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.?)'e", "getvar(trim(str_replace('$','','\\1')));",$line);
    I want that to replace variables in a string with some predefined values I have, well, apparently this code finds the variable ok, but it also reads one illegal character after it. I thought the code was suppose to break when it finds an illegal character, well it does breaks, but it also includes the illegal character in the result.

    Any way to fix this? Thanks.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Move the illegal character in the subpattern outside of it. ie:
    PHP Code:
    $line preg_replace("'\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*).?'e""getvar(trim(str_replace('$','','\\1')));",$line); 


  •  

    Posting Permissions

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