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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.