简体   繁体   中英

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 achieve 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>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM