Last active
February 21, 2016 03:56
-
-
Save chris-muller/7bbab43a082b4853a460 to your computer and use it in GitHub Desktop.
Convert text between newlines into html <p> tags.
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 | |
public function nl2p($string) { | |
$paragraphs = ''; | |
//split copy into pragraphs | |
foreach (explode("\n", $string) as $line) { | |
//trim line and if it isn't empty, add to output | |
if ($line = trim($line)) { | |
$paragraphs .= '<p>' . $line . '</p>'; | |
} | |
} | |
return $paragraphs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment