Skip to content

Instantly share code, notes, and snippets.

@chris-muller
Last active February 21, 2016 03:56
Show Gist options
  • Save chris-muller/7bbab43a082b4853a460 to your computer and use it in GitHub Desktop.
Save chris-muller/7bbab43a082b4853a460 to your computer and use it in GitHub Desktop.
Convert text between newlines into html <p> tags.
<?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