- 论坛徽章:
- 0
|
function html_substr($s,$len) {
$a=preg_split(
[email='@(]*>)@',$s,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_OFFSET_CAPTURE]'@(]*>)@',$s,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_OFFSET_CAPTURE[/email]
);
$str=array();
$stack=array();
$single_tag=explode(' ','br hr img');
$r_len=0;
foreach ($a as $key=>$val) {
if($key%2==0) {
$now_len=strlen($val[0]);
if($now_len+$r_len])*>@isU',$val[0],$ar]'@])*>@isU',$val[0],$ar[/email]
);
if(!in_array($ar[2][0],$single_tag)) {
if($ar[1][0]=='/') array_shift($stack);
else array_unshift($stack,$ar[2][0]);
}
$str[]=$val[0];
}
}
if(!empty($stack)) {
foreach ($stack as $v) {
$str[]='';
}
}
return join('',$str);
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10697/showart_570826.html |
|