Strip_tags extension function-processing html (for collection)-PHP source code

Source: Internet
Author: User
Strip_tags extended function-processing html (for collection) Strip_tags extended function-processing html (for collection)

/*** This function turns HTML into text * converts html to 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 * remove/filter html tags and remove content from tags * Note: $ tags is the opposite when the invert of the label to be retained is 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 ;}
  
 


The above is the strip_tags extension function-processing html (for collection purposes) content. For more information, please follow the PHP Chinese network (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.