i use such regex $msg = preg_replace('/<b>(\w)<\/b>/', '9999', $msg);
to replace <b>test</b>
but it not replace. why?
Notice the plus after \w+
$msg = preg_replace('/<b>(\w+)<\/b>/', '9999', $msg);
try this
$msg = preg_replace('#<b>(\w)*<\/b>#', '9999', $msg);
You're missing the quantity token. That would only match one character long strings between the <b>
tags.
$msg = preg_replace('/<b>(\w*)<\/b>/', '9999', $msg);
Your \w
does not match. I don't find my regex manual right now, but use something like .*
.