shanejeffery86 Posted September 30, 2009 Share Posted September 30, 2009 Hey all. I have a very large soruce of body texts in the database and I need to do a preg_replace all on all of the rows. What I am trying to do is this: 1) Call the function 2) Do a preg_match to see if the String can be found in the source. 3) If it is found, then do a preg_replace on the row body. If not found, then just return the value of the original parameter (as nothing has changed, the value will be the same). Here is my current code to get this done: function changeDirectory($data){ if(preg_match('/_images/uploads/', $data)) return preg_replace('/_images/uploads/', '/sites/default/files/images-from-old-site/', $data); else return $data; } What is happening is that when the function is called, somehow the preg_replace is killing the entire body. It is setting it to blank. And yes, the function is returning to a PHP variable after the fact. Any ideas on what I am doing wrong? Thanks! Quote Link to comment Share on other sites More sharing options...
shanejeffery86 Posted September 30, 2009 Author Share Posted September 30, 2009 Since I am not using REGEX, I am thinking that str_replace might be a better solution here. I will let you guys know how that goes. Quote Link to comment Share on other sites More sharing options...
shanejeffery86 Posted September 30, 2009 Author Share Posted September 30, 2009 Woot! str_replace > preg_replace. Worked perfectly! Solved. 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.