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 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts

    preg replace problem

    Hello,

    I have this line in a mysql function in my PHP app.
    Code:
    $query = preg_replace('#\{(.*)\}#e', 'tab("\1")', $query);
    It is supposed to take everything between { and } and replace with with a table name supplied from the tab() function. Now it works file when I have just one table name, but when I have two table names it functions incorrectly, replacing everything between the first { and the last }.

    For example,

    FROM {table1} t, {table2} j

    would read everything from the t in table1 to the 2 in table2.

    Is there a way to fix this?

    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
    Use the U (ungreedy) modifier:
    PHP Code:
    $query preg_replace('#\{(.*)\}#Ue''tab("\1")'$query); 

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    152
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Perfect, thanks!


  •  

    Posting Permissions

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