tomsseisums
tomsseisums

Reputation: 13367

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?

Upvotes: 1

Views: 295

Answers (1)

jmz
jmz

Reputation: 5479

Try this:

$input = str_replace('</P>', '</p>', $input); # In case of upper case tags
list($first, $next) = explode('</p>', $input, 2);
$first .= '</p>';

Upvotes: 4

Related Questions