Created
April 18, 2019 10:07
-
-
Save bryanthuan/923fa32826f0be9bc0ae4ce3dbb0d406 to your computer and use it in GitHub Desktop.
Simple nl2p (wraps things in paragraph tags as opposed to line breaks - nl2br)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * This wraps blocks of text (delimited by \n) in p tags (similar to nl2br) | |
| * @author Scott Dover <[email protected]> | |
| * @param str | |
| * @return str | |
| */ | |
| function nl2p($string) { | |
| /* Explode based on new-line */ | |
| $string_parts = explode("\n", $string); | |
| /* Wrap each block in a p tag */ | |
| $string = '<p>' . implode('</p><p>', $string_parts) . '</p>'; | |
| /* Return the string with empty paragraphs removed */ | |
| return str_replace("<p></p>", '', $string); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment