Php 将第一段与其他段落分开

Php 将第一段与其他段落分开,php,html,Php,Html,假设我有以下源输出: <p>This is first paragraph</p> <p>This is second paragraph</p> <p>This is third paragraph</p> 我想要达到的是。。。我想把它们分开,第一段变成一个变量,其他的变成另一个变量。比如: $first = "<p>This is first paragraph</p>"; $next = "&

假设我有以下源输出:

<p>This is first paragraph</p>
<p>This is second paragraph</p>
<p>This is third paragraph</p>
我想要达到的是。。。我想把它们分开,第一段变成一个变量,其他的变成另一个变量。比如:

$first = "<p>This is first paragraph</p>";
$next = "<p>This is second paragraph</p><p>This is third paragraph</p>";
因为这些是由TinyMCE和用户输入生成的,所以我永远无法知道用户何时会添加或添加其他标记,这将导致TinyMCE生成新的代码中断\r\n。因此,所有通过查找来拆分它们的解决方案\r\n这次都不起作用

有什么建议吗?

试试这个:

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

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

+1.轻松愉快。iNB4使用DOM解析器等。您可以考虑用PrggSeple“< /p> I',$输入,2来替换前两行,以避免更改$输入。其他不相关的

标记可能会受到str_replace的影响。谢谢,现在就这样做吧+1.轻松愉快。iNB4使用DOM解析器等。您可以考虑用PrggSeple“< /p> I',$输入,2来替换前两行,以避免更改$输入。其他不相关的

标记可能会受到str_replace的影响。谢谢,现在就这样做吧!