Skip to content

Instantly share code, notes, and snippets.

@icco
Created February 25, 2009 20:37
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 icco/70397 to your computer and use it in GitHub Desktop.
Save icco/70397 to your computer and use it in GitHub Desktop.
For converting plain text to html
<?php
/**
Basically is used to convert plain text to html.
@author Nat Welch
*/
function htmlify($str)
{
// replace special characters with HTML entities
$html = htmlspecialchars($str);
//paragraph-ise
$html = "<p>" . str_replace("\n\n", "</p>\n<p>", $html) . "</p>";
// replace multiple spaces with single spaces
$html = preg_replace('/\s\s+/', ' ', $html);
// replace URLs with <a href...> elements
$html = preg_replace('/\s(\w+:\/\/)(\S+)/', ' <a href="\\1\\2" title="\\2">\\1\\2</a>', $html);
return $html;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment