【问题标题】:How to use php preg_replace or preg_match strip <p> that wrap <pre如何使用 php preg_replace 或 preg_match strip <p> 包装 <pre
【发布时间】:2013-06-05 17:34:20
【问题描述】:

我有这个 html

<p>some text.</p>
<p><pre>
<?php sample(); 
$var = 'aaa';
?>
</pre></p>
<p>describe</p>
<p>
<pre>
<html>...</html>
</pre>
</p>

您会注意到&lt;pre&gt;&lt;p&gt; 中是错误的!

我想删除所有包含&lt;pre&gt; 不正常&lt;p&gt; 段落的&lt;p&gt;

如何使用php纠正这个?

【问题讨论】:

    标签: php html preg-replace preg-match preg-match-all


    【解决方案1】:

    我试过了,发现这段代码有效。

    $content = 'as see in question';
    
    $pattern = '#<p>(\\s*)(<pre.*/pre>)(\\s*)</p>#isU';
    $content = preg_replace($pattern, '$2', $content);
    
    echo $content;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-11
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      相关资源
      最近更新 更多