Php string filtering and replacement summary, php string summary. Php string filtering and replacement summary, php string summary this article examples summarizes the php string filtering and replacement methods. Share it with you for your reference. The specific implementation method is as follows: copy php string filtering and replacement summary, php string summary
This example summarizes the php string filtering and replacement methods. Share it with you for your reference. The specific implementation method is as follows:
The code is as follows:
<? Php
Class cls_string_filter {
// Convert \ n
-- Interesting?
Static public function nl2br ($ string ){
Return nl2br ($ string );
}
// Set
Convert to \ n
Static public function br2nl ($ string ){
$ Array = array ('
','
');
Return str_replace ($ array, "\ n", $ string); // string replacement
}
// Retain only one space
Static public function merge_spaces ($ string ){
Return preg_replace ("/\ s (? = \ S)/"," \ 1 ", $ string );//(? = Pattern) example: abc (? = Kk) can match abckk, but cannot match abcdd
}
// Multiple
Retain only one
Static public function merge_brs ($ string ){
Return preg_replace ("/(( ) +)/I ","
", $ String); // ---"/"Why is it 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 the start and end characters of a 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 strings