http://www.yahoo.com/' | .'
Yahoo Server
Search Engine'; | $allowed_tags = array('
',''); | echo $ct->dropHTML($text,$allowed_tags); | echo $ct->shortText($text,10); | | ?> -----------------------------------------------------------------------------------*/ class SDConvertText { /************************************************** * this function will activate all functions * in this class except of shortText function **************************************************/ function convertAll($str,$allowed_tags){ $str = $this->dropHTML($str,$allowed_tags); $str = $this->activateLinks($str); return $str; } /**************************************************** * Takes a string, and does the reverse of the PHP * standard function htmlspecialchars(). ****************************************************/ function undo_htmlspecialchars($string) { $string = preg_replace("/>/i", ">", $string); $string = preg_replace("/</i", "<", $string); $string = preg_replace("/"/i", "\"", $string); $string = preg_replace("/&/i", "&", $string); return $string; } /************************************************** * this function will activate all links and * email addresses with tag **************************************************/ function activateLinks($str) { $str = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1', $str); $str = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1\\2', $str); $str = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','\\1', $str); return $str; } /************************************************** * this function will drop HTML tags except of * of tag in $allowed_tags varible * can be also array of tags **************************************************/ function dropHTML($str,$allowed_tags = ''){ if(is_array($allowed_tags)){ foreach($allowed_tags as $key => $value) $tags .= $value; return $str = strip_tags($str,$tags); }else{ return strip_tags($str,$allowed_tags); } } /************************************************** * This function shortens text into $length at most. * If the text is longer, puts an ellipsis at the end. **************************************************/ function shortText($str,$length){ return strlen($str) > $length ? preg_replace('/\s\S*$/','...',substr($str,0,$length - 3)) : $str; } } ?>