Several useful PHP string filtering and conversion functions

Source: Internet
Author: User

 

1 <? PHP
2
3 Nl2br (); // \ N to <br/>
4 Addslashes (); Stripslashes (); // Escape special characters during database operations
5
6 Chop (); // Removes spaces on the right of the string.
7 Trim (); // Removes all spaces in the string.
8 Ltrim (); // Removes spaces on the left of the string.
9
10 Htmlspecialchars (); // Convert '$', '"', '<', '>' to the corresponding HTML object.
11 Htmlentities (); // Convert all HTML tags to corresponding HTML entities
12
13 Array   Explode ( String Separator ,   String Str ); // Split string
14 String   Implode ( String Separator ,   Array ARR ); // Connection string
15  
16 Strtoupper (); Strtolower (); // Case sensitivity
17 Ucfirst (); // Only converts the first character to uppercase.
18 Ucwords (); // Converts the first letter of each word to uppercase.
19 ?>

 

Replace spaces with regular expressions.CodeYes \ s.

 

1 <? PHP
2  
3 $ String   =   " Ooo I am a space " ;
4 $ String   =   Preg_replace ( " /(\ S + )/ " , '' , $ String ); // Replace all spaces
5 Echo   $ String ;
6  
7 ?>

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.