Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created May 9, 2017 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/6e5dea80fd022a16e1f8772af76e4cb4 to your computer and use it in GitHub Desktop.
Save Kcko/6e5dea80fd022a16e1f8772af76e4cb4 to your computer and use it in GitHub Desktop.
Wrap text into paragraphs
<?php
$text = <<<TEXT
Morbi nisl tortor, consectetur vitae laoreet eu, lobortis id ipsum. Integer scelerisque blandit pulvinar. Nam tempus mi eget nunc laoreet venenatis. Proin viverra, erat at accumsan tincidunt, ante mi cursus elit, non
congue mauris dolor ac elit. Maecenas mollis nisl a sem semper ornare. Integer nunc purus, dapibus nec dignissim sed, dictum eget leo. Etiam in mi ut erat pretium fringilla sed
TEXT;
$paragraphedText = "<p>" . implode( "</p>\n\n<p>", preg_split( '/\n(?:\s*\n)+/', $text ) ) . "</p>";
echo $paragraphedText;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment