如何用preg_replace_callback()替换代码? (/ e)的

时间:2014-02-10 12:52:30

标签: php regex preg-replace preg-replace-callback

$in = '(<(/?(?:strong|p|em|a|ol|ul|li|img|iframe)\b.*?)>)ie';

$contenu = preg_replace($in, "'<'.html_entity_decode('$1',ENT_QUOTES,'UTF-8').'>'", $contenu);

1 个答案:

答案 0 :(得分:0)

$pattern = '~&lt;(/?(?:strong|p|em|a|ol|ul|li|img|iframe)\b.*?)&gt;~is';

$contenu = preg_replace_callback($pattern, function ($m) {
    return '<' . html_entity_decode($m[1], ENT_QUOTES, 'UTF_8') . '>'; }, $contenu);