tqla Posted August 27, 2008 Share Posted August 27, 2008 Hello, is it possible to combine the following 2 preg_replace's into 1? preg_replace('/{{FirstName}}/i', "$i_FirstName", $txtbody); preg_replace('/{{LastName}}/i', "$i_LastName", $txtbody); Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 Why are you using preg_replace() for that instead of str_replace? Quote Link to comment Share on other sites More sharing options...
tqla Posted August 27, 2008 Author Share Posted August 27, 2008 it's inherited code, 1000's of lines of it so I am hesitant to make a drastic change. This is already there: $txtbody = preg_replace('/{{FirstName}}/i', "$i_FirstName", $txtbody); I wish to add another to replace Lastname. So I was hoping that I can do 2 in one shot. Is this possible? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 $patten = array('/{{FirstName}}/i', '/{{LastName}}/i'); $replace = array($i_FirstName, $i_LastName); $txtbody = preg_replace($pattern, $replace, $txtbody); Just to let you know, that's a highly inefficient system. Are you using it for templating? I'd suggest using something like Smarty, because your page load times will suffer if you keep hardcoding those in like that. Quote Link to comment Share on other sites More sharing options...
tqla Posted August 27, 2008 Author Share Posted August 27, 2008 OIC. Thanks DarkWater. I'm sure you're right about Smart/Curl but it's an old website that I cannot redo. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.