PHP头条
热点:

php切割html字符串,自动加上未结束的html标签-PHP源码


/*截取html字符串
 * @param $s 字符串
 * @param $zi 长度
 * @param $ne 没有结束符的html标签
 */
function G_htmlcut($s,$zi,$ne=',br,hr,input,img,'){
	$s=preg_replace('/\s{2,}/',' ',$s);
	$os=preg_split('//',$s);
	preg_match_all('//',$s,$or);
	$s='';
	$tag=array();
	foreach($os as $k => $v){
		if($v!='' && $v!=' '){
			$l=strlen($v);
			for($i=0;$i 127){
					$s.=$v[$i].$v[++$i].$v[++$i];
				}else{
					$s.=$v[$i];
				}
				$zi--;
				if($zi < 1){
					break 2;	
				}
			}
		}
		preg_match('/]+)[\s>]{1}/',$or[0][$k],$t);
		$s.=$or[0][$k];
		if(strpos($ne,','.strtolower($t[1]).',')===false && $t[1]!='' && $t[1]!=' '){
			$k=array_search('',$tag);
			if($k!==false){
				unset($tag[$k]);
			}else{
				array_unshift($tag,'');
			}
		}
	}
	return $s.implode('',$tag);
}

www.phpzy.comtrue/phpyy/44742.htmlTechArticlephp切割html字符串,自动加上未结束的html标签-PHP源码 /*截取html字符串 * @param $s 字符串 * @param $zi 长度 * @param $ne 没有结束符的html标签 */function G_htmlcut($s,$zi,$ne=,br,hr,input,img,){$s=preg_repla...

相关文章

PHP之友评论

今天推荐