<?php
//html 中显示
$str ='<span>fdsfsdf</span><a href="#">href</a>';
echo htmlspecialchars($str).'<Br>';
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;
}
|