| This article describes how to organize php strings, including accessing a single character, deleting blank characters, and html escaping. For more information, see.
Php allows you to access, organize, and transcode strings in strings.
1. to access a single character in php, you can regard the string as an array of characters and directly access the string 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 trim (), ltrim (), and rtrim () functions to delete the white spaces 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. use strtolower () to convert 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 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 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 into a plus sign, and convert other values into url strings. The former converts the space into a plus sign, and the latter converts rawurlencode () and rawurldecode () convert a space to % 20, that is, a normal url string. convert the space to a url string. convert the space to % 20, and convert the space to % 20.
6. SQL escaping the two most relevant databases (mysql and postgresql) of php are escape characters using backslashes (defined by oracle and not tested by other databases ), add the backslash using the addslashes () function in php and delete the backslash using the stripcslashes () function. |