php - str_replace matches incorrect part of string -


i'm having issues str_replace, when trying automatically put backticks around table- , fieldnames.

assuming have following arrays:

$match = array('rooms.roomid','r_rooms.roomid'); $replace = array('`rooms`.`roomid`','`r_rooms`.`roomid`'); $subject = 'rooms.roomid = r_rooms.roomid';  str_replace($match,$replace,$subject); 

the result expect is:

`rooms`.`roomid` = `r_rooms`.`roomid` 

but instead i'm getting this:

`rooms`.`roomid` = r_`rooms`.`roomid` 

however if change r_rooms r_ooms, result expected

`rooms`.`roomid` = `r_ooms`.`roomid` 

i've tried same precedure, using preg_replace, gives me same output aswell.

it correct. first replaced value rooms.roomid rooms.roomid (2 times) change order of $match , $replace tables expected result

$match = array('r_rooms.roomid','rooms.roomid'); $replace = array('`r_rooms`.`roomid`','`rooms`.`roomid`'); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -