Jump to content

[SOLVED] Run str_replace() until a certain piece of text is found.


keeps21

Recommended Posts

I'm currently running a str_replace() function on variable which contains a string. The str_replace() function currently replaces the path to images. basically searches for ../ and replaces with ./

 

What I need to do is run the str_replace() function until the following comment in the string is reached

 

<!-- STOP replacing path -->

 

Not sure how to do this though. Can anyone give me a pointer?

 

Any help would be appreciated.

Cheers.

Split the string into two parts using the "<!-- STOP replacing path -->" as the separator

$strParts = explode("<!-- STOP replacing path -->",$string);

run your search replace against $strParts[0].

implode it all back together again

$string = implode("<!-- STOP replacing path -->",$strParts);

 

 

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.