Php filter string function _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php filters string functions. Share a php string filter function with the following code: functionStripHTML ($ string) {$ patternarray (script [^] *?. *? Scriptsi, style [^] *?. *? Stylesi, [!] *? [^] *? Si shares a php string filter function with the following code:

function StripHTML($string){$pattern=array ("'
 
  ]*?>.*?《script》'si", "'
  
   ]*?>.*?'si",  "'<[\/\!]*?[^<>]*?>'si",  "'([\r\n])[\s]+'",  "'&(quot|#34);'i",  "'&(amp|#38);'i",  "'&(lt|#60);'i",  "'&(gt|#62);'i",  "'&(nbsp|#160);'i",  "'&(iexcl|#161);'i",  "'&(cent|#162);'i",  "'&(pound|#163);'i",  "'&(copy|#169);'i",  "'&#(\d+);'e");$replace=array ('', '', "\\1", '', "&", "<", ">", ' ', chr(161), chr(162), chr(163), chr(169), "chr(\\1)");return preg_replace ($pattern, $replace, $str);}
  
 
Articles you may be interested in
  • Some powerful string processing functions forgotten by php
  • Php's most precise string length truncation function
  • Php string replacement function str_replace is faster than preg_replace
  • Summary of String Functions in PHP
  • PHP string escape functions (addslashes, stripslashes)
  • Js array to string, js string to array method summary
  • Php extracts numbers from strings
  • PHP generates continuous numbers (letters) array function range () analysis, PHP lottery program function

Using function StripHTML ($ string) {$ pattern = array ("'script [^] *?. *? /Script 'Si "," 'style [^] *?. *? /Style 'Si "," '[\/\!] *? [^] *? 'Si "...

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.