详情页

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

时间:2023年10月04日

编辑:佚名

函数:
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
相关文章
猜你需要