what is the simplest method to do the following
Look at a block of text and anywhere it finds %sometxt% replace that with something else,
So basically any text that is enclosed within a set of percentage signs similar to how Smarty do this?
The simplest method you asked for:
$blockOfText = str_replace('%sometxt%', 'something else', $blockOfText);
You just replace it with str_replace
.
$newText = preg_replace('/%.+?%/', 'replacedText', $text);
Should do it. replacedText
needs to be whatever you want to replace %sometxt%
with.
The regexp %.+?%
means
Fine a
%
sign, followed by any character until I find another%
sign.
The ?
makes the expression 'lazy', so it will match up to the first occurrence of %
.