i have an array containing some phrases:
$phrases = array(
'phrase number one',
'phrase number two',
'phrase three',
'phrase foo',
'bar (foo 1.2.3)'
);
$text may contain part of phrase or exact phrase or phrase in the bbcode tags like this:
$text = '
[b]phrase number one[/b]
[color="red"]phrase foo[/color]
phrase three
[b][color="red"]phrase foo[/color][/b]
Lorem ipsum...
[u][color="green"]phrase three[/color][/u]
[url="http://example.com"]bar (foo 1.2.3)[/url]
[url="http://example.com"][b]bar (foo 1)[/b][/url] dolor sit amet...
phrase number two
';
i need to exclude that and search only exact phrase without bbcodes around it and replace: "phrase" => [other_bbcode]phrase[/other_bbcode]
foreach($phrases AS $phrase)
{
$phrase = preg_quote($phrase, "#");
if(preg_match('#(' . $phrase . ')+?#si', $text, $matches))
{
$text = preg_replace('#' . $matches[0] . '#i', '[other_bbcode]$matches[0][/other_bbcode]', $text);
}
}
phrase three and phrase number two => replace
the rest text => stay as is
how to exclude phrases in bbcodes?
Thanks