vee
vee

Reputation: 4755

How to use php preg_replace or preg_match strip <p> that wrap <pre

i have this html

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

you will notice that <pre> is in <p> that is wrong!

i want to remove all <p> that wrap <pre> not normal <p> paragraph.

how to use php correct this?

Upvotes: 0

Views: 300

Answers (1)

vee
vee

Reputation: 4755

i tried and found that this code works.

$content = 'as see in question';

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

echo $content;

Upvotes: 1

Related Questions