©) and converts < and > into * entities. If wanted, all p's and br's can be removed as well, * just uncomment line 18. */ function convert2char($string) { encodeEntities($string); escapeXML($string); // xml2nl($string); return $string; } /** * Used to strip all \ when a preview is performed. */ function stripPOST() { foreach ($_POST as $key => $value) { if (is_string($value)) $_POST[$key] = stripslashes($value); } } /** * This function can be used to remove all p's and br's from * a text. Problem: it removes user defined p's as well. */ function xml2nl(&$string) { $string = str_replace(array('
', '
', '\s*?
|", //Remove blank segments //Handle blockquotes "/]*)>/i", "||i", //Remove paragraphs around block elements "!
\s*(?(?:ul|ol|li|p|dl|img|h[1-6])[^>]*>)!", "!(?(?:ul|ol|li|p|dl|img|h[1-6])[^>]*>)\s*
!", //Line breaks "/(?)\n(?!(\n)|(\<))/i", "/\\1
\n\n", '', "", "\\1", "\\1", "", "
/i', "\n \n", $str);
return str_replace('
', '', $str);
}
/**
* Fix p's that are nested inside li's.
*/
function pfix($str) {
$str = str_replace('\\"', '"', $str); //Manually remove slashes.
if (strstr($str, '
') && strpos($str, '
') > 0) $str = '
'. $str . '
'; return $str; } /** * Escape stand-alone & by addning & to them */ function decodeEntities(&$string) { $string = preg_replace('/&(\s|\n)/', '&\\1', $string); } /** * Convert all & into &. Used to print entities AS entities and NOT AS * the symbol they represent. E.g. © should be displayed, NOT ©. */ function encodeEntities(&$string) { $string = str_replace('&', '&', $string); return $string; } /** * This method does a simple replacement of < and >. Used to make the text * editable in a textarea. */ function escapeXML(&$string) { $string = str_replace(array('<', '>'), array('<', '>'), $string); } ?>