maccaj51
asked on
php and preg replace
Hi Experts,
Why does this add two << around the preg replace...
I just want to add strong to first para only
$text = preg_replace('<p>', '<p><strong>', $text, 1);
$text = preg_replace('</p>', '</strong></p>', $text, 1);
Cheers
Why does this add two << around the preg replace...
I just want to add strong to first para only
$text = preg_replace('<p>', '<p><strong>', $text, 1);
$text = preg_replace('</p>', '</strong></p>', $text, 1);
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ray,
Thanks for the information. I would class myself a little above beginner so will have a look...
Is there any reason why i should accept and use hernst42 answer?
Thanks for the information. I would class myself a little above beginner so will have a look...
Is there any reason why i should accept and use hernst42 answer?
Sure! Just looking at it, I am fairly sure it works. In some cases the wickets < and > may be treated as meta-characters, but this is not one of them.
ASKER
Many Thanks hernst42
& Ray!
& Ray!
You may also find that certain "meta characters" need to be escaped by prepending them with a backslash. PHP is inconsistent in its application of this rule. Enlightening reading here:
http://php.net/manual/en/reference.pcre.pattern.syntax.php