Global preg_replace?

Hi Sitepoint!

I want to cut out everything from $a to $b in a text variable, eg.
$text=“some text start text in between end text later on”;

so $text would be “some text text later on”

is there a way to do this in php? I know how to do it in perl but php doesnt seem to have a global flag…

Try str_replace(). If you want to use regex though, check out [URL=]preg_replace() and [URL=]preg_match_all().

Good luck!

can I do that with str_replace? it doesnt look like it allows that wildcard-style matching.

$string = preg_replace('/\\bstart\\b.*\\bend\\b/', '', $string);

[fphp]preg_replace[/fphp] is global unless you specify the $limit parameter.