Skip to content

Instantly share code, notes, and snippets.

@ewistrand
Last active February 17, 2020 20:12
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 ewistrand/453553c49f27f61d508f883647f6d6d5 to your computer and use it in GitHub Desktop.
Save ewistrand/453553c49f27f61d508f883647f6d6d5 to your computer and use it in GitHub Desktop.
Turn line breaks into paragraph tags
if(! function_exists('nl2p')) {
function nl2p($str) {
$arr = explode("\n", $str);
$out = '';
for($i = 0; $i < count($arr); $i++) {
if(strlen(trim($arr[$i])) > 0)
$out .= '<p>' .trim($arr[$i]) . '</p>';
}
return $out;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment