Reputation: 1762
I have the following to replace uppercase HTML tags with lowercase ones.
$output = preg_replace("%<(/?[A-Z].*?)>%s",strtolower('$1'),$output);
The matching seems to be working well (in my RegEx testing site), but the replacement isn't.
<EM>TEST</EM> becomes EMTEST/EM
Hoping someone can point me in the right direction on this.
Upvotes: 2
Views: 2825
Reputation: 173622
$output = preg_replace("%<(/?[A-Z].*?)>%se", "'<' . strtolower('\\1') . '>'",$output);
Edit: forgot to mention that you should NOT use preg
for HTML stuff :) DOMDocument is a far better choice.
Upvotes: 1
Reputation: 324720
You are calling strtolower
on "$1"
and then using the result (which is just $1
again) to replace to.
Instead, use preg_replace_callback
and have the callback be: function($m) {return strtolower($m[0]);}
Upvotes: 3