Php string filtering and replacement summary, php string summary _ PHP Tutorial

Source: Internet
Author: User
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

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.