Hi, I'm trying to remove some deprecated code from a site. Can anyone tell me the preg equivalent of
ereg_replace("<b>","<strong>",$content);
Thanks.
Hi, I'm trying to remove some deprecated code from a site. Can anyone tell me the preg equivalent of
ereg_replace("<b>","<strong>",$content);
Thanks.
There seems to be no need for regular expressions at all.
a simple str_replace would do:
$cleaned = str_replace ('<b>', '<strong>', $unCleaned);
If you need more complicated replacements, for example checking the attributes, you could do:
$cleaned = preg_replace('/<b(\s[^>]*)?>/', '<strong\\1>', $unCleaned);
But this is by no means perfect; something like <div title="foo->bar"></div>
would break the regular expression.
A PCRE equivalent to your ERE regular expression would be:
preg_match("/<b>/", "<strong>", $content)
But as Jacco already noted you don’t need a regular expression at all as you want to replace a constant value.