Jump to content

string replace to add a defined variable


denoteone

Recommended Posts

I need to update the img paths for all the images of my site. The current image tags are in the body variable in a database.

 

I defined a base url with the define() function.

 

	
$body = str_replace("<img src=\"'. constant(\"BASE_URL\") .'", "<img src=\"", $content[$counter]['body']);
	echo '<div class="article-teaser">'. $body .'</div>';

 

I am having issues. If anyone can help that would be great.  I have a feeling it has something to do with the quotes.

 

Thanks!

I think more information is going to be needed to help you. Things need a bit more context.

 

Right now, all that can be seen is that you're looking for a string that looks EXACTLY as I've typed it below:

 

<img src="'. constant("BASE_URL") .'

 

And you want to replace it with the following string exactly as I've typed it:

 

<img src="

 

And you're searching in a string contained in $content[$counter]['body']

 

Without knowing what's in $content[$counter]['body'] or what's going wrong, there's no way to help you.

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.