Jump to content

preg_replace -- help needed


shanejeffery86

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/176063-preg_replace-help-needed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.