Separating first paragraph from others
Let's say, that I have the following source output:
<p>This is first paragraph</p>
<p>This is second paragraph</p>
<p>This is third paragraph</p>
What I want to ac开发者_如何学Pythonhieve is... I want to split them, first paragraph goes into one variable, others into other. Like:
$first = "<p>This is first paragraph</p>";
$next = "<p>This is second paragraph</p><p>This is third paragraph</p>";
Because those are generated by TinyMCE and user input, I can never know when user will add <br />
or other tags, which will cause TinyMCE to generate a new code-break \r\n
. Therefore, all the solutions which split them by looking for \r\n
won't work this time.
Any advice?
Try this:
$input = str_replace('</P>', '</p>', $input); # In case of upper case tags
list($first, $next) = explode('</p>', $input, 2);
$first .= '</p>';
精彩评论