php string filtering and replacement summary, php string summary
The example in this article summarizes the methods of filtering and replacing strings in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
Copy code The code is as follows:
class cls_string_filter{
//Convert n to
--囧, is this interesting?
static public function nl2br($string){
Return nl2br($string);
}
//Convert
into n
static public function br2nl($string){
$array = array('
','
');
Return str_replace($array,"n",$string);//String replacement
}
//Reserve only one of multiple spaces
static public function merge_spaces($string){
Return preg_replace("/s(?=s)/","\1",$string);//(?=pattern) Example: abc(?=kk) can match abckk, but not abcdd
}
//Multiple
only keep one
static public function merge_brs($string){
return preg_replace("/((
)+)/i","
",$string);//---Why is "/" also escaped
}
//Filter the html tags in the string
static public function strip_tags($string){
Return strip_tags($string);
}
//Convert the string to lowercase--/--uppercase
static public function strtolower($string){
Return strtolower($string);
}
static public function strtoupper($string){
return strtoupper($string);
}
//Filter specific characters at the beginning and end of the string
static public function trim($string,$char_list='\\s'){
$find = array('/[^-]\]/S','/\{4}/S','///');
$replace = array('\\\0','\','/');
$char = preg_replace($fine,$replace,$char_list);
$pattern = '^['.$chars.']*|['.$chars.']';
Return preg_replace("/$pattern/sSD",'',$string);
}
//Filter the /is";
Return preg_replace($reg,'',$string);
}
//Filter html dangerous codes in strings
static public function strip_html_tags($string){
$reg = "/(/?)/(script|iframe|style|html|body|title|meta|?|%)([^>]*?>)/is";
Return preg_replace($reg,'',$string);
}
}
?>
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/947912.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947912.htmlTechArticleSummary of php string filtering and replacement, php string summary This article summarizes the methods of php string filtering and replacement . Share it with everyone for your reference. The specific implementation method is as follows: Copy...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn