【问题标题】:How can I replace the code with preg_replace_callback()? (/e) [duplicate]如何用 preg_replace_callback() 替换代码? (/e) [重复]
【发布时间】:2014-03-07 19:38:26
【问题描述】:
$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);

【问题讨论】:

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


【解决方案1】:
$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);

【讨论】:

  • 谢谢,这很好。
猜你喜欢
  • 2013-10-15
  • 2014-02-16
  • 2013-03-05
相关资源
最近更新 更多