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
Post a Comment