PHP采集数据后,处理采集数据的函数

函数:

function xxfseo_body($body){
	$body = preg_replace('~<(?!img)(\w+)\s+[^>]*>~i','<$1>', $body);
	$body = preg_replace("/<(iframe.*?)>(.*?)<(\/iframe.*?)>/si", "", $body);
	$body = preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si", "", $body);
	$body = preg_replace("/<(script.*?)>(.*?)<\/script>/si", "", $body);
	$body = preg_replace("~<(|/)form([^>]*)>~i", "", $body);
	$body = preg_replace("~<input([^>]*)>~i", "", $body);
	$body = preg_replace("/<(textarea.*?)>(.*?)<\/textarea>/si", "", $body);
	$body = preg_replace("/<(botton.*?)>(.*?)<\/botton>/si", "", $body);
	$body = preg_replace("/<(select.*?)>(.*?)<\/select>/si", "", $body);
	$body = preg_replace("~<(|/)div([^>]*)>~i", "", $body);
	$body = preg_replace("~<(|/)span([^>]*)>~i", "", $body);
	$body = preg_replace("~<(|/)font([^>]*)>~i", "", $body);
	$body = preg_replace("~<(|/)a([^>]*)>~i", "", $body);
	$body = preg_replace("~<style[^>]*>(.*?)</style>~iUs", "", $body);
	$body = preg_replace("~<xml[^>]*>(.*?)</xml>~iUs", '', $body);
	$body = preg_replace("~<(|/)b>~i", "", $body);
	$body = preg_replace('~<!--(.*)-->~','', $body);
	$body = preg_replace('~<!--\[if [^\]]+\]>(.*?)<!\[endif\]-->~iUs','', $body);
	$body = preg_replace('~<(\w+)[^>]*>\s*</\\1>~Us', '', $body);
	$body = preg_replace("~[\r\n]+~",'', $body);
	$body = preg_replace("~>\s*~",'>', $body);
	$body = str_replace('</object>','', $body);
	return trim($body);
}

非常好用,适合采集后处理比较复杂的html

© 版权声明
THE END
喜欢就支持一下吧
点赞9
评论 抢沙发

请登录后发表评论

    暂无评论内容