PHP learning to sort strings. 1. to access a single character in PHP, you can regard the string as an array of characters and use the array access method to access the string directly. For example, $ str [0]. Note that, for example
1. access a single character
In PHP, strings can be treated as an array of characters, and strings can be accessed directly using the array access method. For example, $ str [0].
Note that if the character is not an ASCII code, access may fail. Because such access can only get one byte.
2. delete blank characters
In PHP, you can use the trim (), ltrim (), and rtrim () functions to delete the blank characters starting or ending with a string.
Trim () is used to delete the spaces before and after the characters; ltrim () is used to delete the white spaces on the left side of the characters; rtrim () is used to delete the white spaces on the right side of the characters.
By default, the following characters are deleted: Space (| Ox20), TAB (\ n | Ox09), line feed (\ n | OxOA), and press enter (\ r | 0x0D), empty characters (\ 0 | Ox00 ).
You can also specify it in the parameter.
3. change the case sensitivity.
Strtolower () converts the entire string to lowercase.
Strtoupper () converts the entire string to uppercase.
Ucfirst () converts the first character of the string to uppercase, and other characters remain unchanged.
Ucwords () converts the first character of each word in a string to uppercase, and other characters remain unchanged.
4. HTML escape
HTML escaping refers to converting a string into a string used for HTML display. In this regard, PHP has two functions to implement this function.
Htmlentities () converts all characters except spaces to HTML.
Htmlspecialchars () converts necessary (with symbols &, double quotation marks, single quotes, greater than signs, less than signs) into HTML format.
5. URL escape
URL escape refers to converting a string into a URL string. In this regard, PHP has two functions to implement this function.
Urlencode () and urldecode () convert spaces to the plus sign, and convert other values to URL strings. convert the former to the other, and convert the latter to the other.
Rawurlencode () and rawurldecode () convert the space to % 20, that is, a normal URL string. convert the rest to a URL string. convert the former to the other, and reverse convert the other to the URL string.
6. SQL escape
The two most relevant PHP databases (MySQL and PostgreSQL) are escape characters using backslashes (defined by Oracle and not tested by other databases). In this case, addslashes () is used in PHP () use the stripcslashes () function to delete the backslash.
References:
PHP programming, Chapter 4, Chapter 4 string, accessing a single string, sorting strings, encoding and escaping
Http://www.bkjia.com/PHPjc/323156.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323156.htmlTechArticle1. to access a single character in PHP, you can regard the string as an array of characters, you can directly access the string using the array access method. For example, $ str [0]. Note that, for example...