function likepre ($string) { $string = str_replace('"','"',$string); $string = str_replace("'",''',$string); $string = str_replace("<","<",$string); $string = str_replace(">",">",$string); $string = str_replace("\t"," ",$string); //換為全角空格 $string = str_replace(" "," ",$string); //兩個半角空格換為全角空格 $string = nl2br($string); return $string; }
From:笨笨林@PHPChina
Please follow and like us:
用 htmlspecialchars 這個函數也可以