PHP头条
热点:

strip_tags延伸函数-处理html(采集用的上)-PHP源码


strip_tags延伸函数-处理html(采集用的上)

/** 
 * This function turns HTML into text  * 将html转化为txt   
*/ 
function html2txt($document) {     
$search = array ('@]*?>.*?《script》@si', 
// Strip out javascript                     
'@]*?>.*?@siU', 
// Strip style tags properly                     
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags                     
'@@' )// Strip multi-line comments including CDATA     ;     
$text = preg_replace ( $search, '', $document );     
return $text; }  
/**  
* removes the HTML tags along with their contents  
* 移除/过滤html标签并且移除标签内的内容  
* 注:$tags为需要保留的标签  invert为true时结果相反  
*/ 
function strip_tags_content($text, $tags = '', $invert = FALSE) {    
 preg_match_all ( '/<(.+?)[\s]*\/?[\s]*>/si', trim ( $tags ), $tags );     
 $tags = array_unique ( $tags [1] );           
 if (is_array ( $tags ) and count ( $tags ) > 0) {         
 if ($invert == FALSE) {             
 return preg_replace ( '@<(?!(?:' . implode ( '|', $tags ) . ')\b)(\w+)\b.*?>.*?@si', '', $text );       
   } else {             
   return preg_replace ( '@<(' . implode ( '|', $tags ) . ')\b.*?>.*?@si', '', $text );         }    
    } elseif ($invert == FALSE) {        
     return preg_replace ( '@<(\w+)\b.*?>.*?@si', '', $text );    
      }     
     return $text; 
     }


以上就是strip_tags延伸函数-处理html(采集用的上)的内容,更多相关内容请关注PHP中文网(www.php1.cn)!

www.phpzy.comtrue/phpyy/45509.htmlTechArticlestrip_tags延伸函数-处理html(采集用的上)-PHP源码 strip_tags延伸函数-处理html(采集用的上) /** * This function turns HTML into text * 将html转化为txt */ function html2txt($document) { $search = array (@ ]*?>...

相关文章

PHP之友评论

今天推荐