php 过滤html标签 截取部分内容

fdsfsdfhref';
echo htmlspecialchars($str).'
'; echo strip_tags($str); ?> //编辑器中的内容 $active = $this->truncate($list['content'],510); //截取html方法: function truncate($string,$length,$append = true){ $string = trim($string); $strlength =strlen($string); if ($length == 0 ||$length >=$strlength){ return $string; }elseif ($length < 0){ $length =$strlength +$length; if ($length < 0) { $length =$strlength; } } if (function_exists('mb_substr')){ $newstr = mb_substr($string, 0,$length,"UTF-8"); }elseif (function_exists('iconv_substr')){ $newstr = iconv_substr($string, 0,$length,"UTF-8"); }else{ for($i=0;$i<$length;$i++){ $tempstring=substr($string,0,1); if(ord($tempstring)>127){ $i++; if($i<$length){ $newstring[]=substr($string,0,3); $string=substr($string,3); } }else{ $newstring[]=substr($string,0,1); $string=substr($string,1); } } $newstr =join($newstring); } if ($append &&$string !=$newstr){ $newstr .='...'; } return $newstr; }

你可能感兴趣的:(HTML,PHP)