How can I return the first x paragraphs from a string using PHP? They're seperated by \r\n but can be put into <p></p> tags if needed.
//split $s into paragraphs
$a = explode("\r\n", $s);
//extract the first $x paragraphs only
$a = array_slice($a, 0, $x);
//rejoin the paragraphs into a single string again
$s = implode('\r\n', $a);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With