preg_replace:将空格添加到段落中

Can i add whitespace into all paragraphs?

I have a string like this:

<p>1st paragraph</p>
<p></p>
<p>2nd paragraph</p>
<p></p>
<p>3rd paragraph</p>

and i want get the result like a white space inside all paragraphs

<p> 1st paragraph</p>
<p> </p>
<p> 2nd paragraph</p>
<p> </p>
<p> 3rd paragraph</p>

does someone know how to do it with preg_replace or something else better?

The obvious solution to this is:

<?php
$markup = <<<HTML
<p>1st paragraph</p>
<p></p>
<p>2nd paragraph
which spans over
three line</p>
<p></p>
<p>3rd paragraph</p>
HTML;

$result = preg_replace('|<p>(.*?)</p>|us', '<p> $1</p>', $markup);
var_dump($result);

The output of above code is:

string(111) "<p> 1st paragraph</p>
<p> </p>
<p> 2nd paragraph
which spans over
three line</p>
<p> </p>
<p> 3rd paragraph</p>"