触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > PHP去除HTML,切取字符串长度

PHP去除HTML,切取字符串长度

<?php
function delete_html($str){  //清除HTML代码、空格、回车换行符
         //trim 去掉字串两端的空格
         //strip_tags 删除HTML元素
         $str = trim($str); 
         $str = preg_replace('/<script[^>]*?>(.*?)<\/script>/si', '', $str); 
         $str = preg_replace('/<style[^>]*?>(.*?)<\/style>/si', '', $str);
         $str = strip_tags($str,""); 
   $str = ereg_replace("\t","",$str); 
         $str = ereg_replace("\r\n","",$str); 
         $str = ereg_replace("\r","",$str); 
         $str = ereg_replace("\n","",$str); 
         $str = ereg_replace(" ","",$str); 
         $str = ereg_replace("&nbsp;","",$str); 
         return trim($str); 
    }
 
function cnsubstr($str,$strlen=10)
{if(empty($str)||!is_numeric($strlen))
{return false;}if(strlen($str)<=$strlen)
{return $str;}//得到第$length个字符 并判断是否为非中文 若为非中文//直接返回$length长的字符串
$last_word_needed=substr($str,$strlen-1,1);
if(!ord($last_word_needed)>128)
{$needed_sub_sentence=substr($str,0,$strlen);
return $needed_sub_sentence;}
else{for($i=0;$i<$strlen;$i++){if(ord($str[$i])>128)
{$i++;}}//end of for
$needed_sub_sentence=substr($str,0,$i);
return $needed_sub_sentence;}
}
?>

<? $bbb= delete_html($rspro->Fields(content)->value);?>
<? $ccc= cnsubstr($bbb,100);?>
<? echo $ccc;?>


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com