Syntax
String can be defined in three methods
''(Single quotes)" "(double quotes) <(delimiter)
Escape sequences can be interpreted \
The biggest feature of double quotation marks is that the variable name will be replaced by the variable value
The delimiters can output HTML format as they are.
You can print strings in either of the following ways:
ECHO is a language structure rather than a real function. The difference between ECHO and print is that it can accept multiple parameters.
Print syntax bool (Boolean row) print (string AGR) function output string if successful return 1 failed return 0 columns if the client's browser suddenly fails during transmission will cause failure
String processing functions
Ltrim syntax format: String ltrim (string Str); Delete leading spaces of a string
Rtrim syntax format: String rtrim (string Str); Delete the suffix space of the string
Trim syntax format: String rtim (string Str); Delete spaces at both ends of grandfather wear
Strrev syntax format: String strrev (string Str); reverse a string to reverse the string
Strtolower syntax format: String strtolower (string Str); converts all strings to lowercase letters.
Strtoupper syntax format: String strtoupper (string Str); converts all strings to uppercase
Ucfirst syntax format: String ucfirst (string Str); change the first letter of the string to uppercase
Ucworde syntax format: String ucworde (string Str); change the first letter of each character in the string to uppercase.
Format the string for display
Sprintf this function formats strings
Sprintf () syntax Format String sprintf (string format, mixed [ARGs]...)
Example:
$ A = sprintf ("% '* 6 s", "KKK ")
Echo $;
Output result: *** KKK
The integer B is converted into binary.
The C integer is converted to the corresponding ASCII character.
D integer to decimal place.
F returns a single precision number to a floating point number.
O integer to octal.
S is converted into a string.
Convert an integer to a lowercase hexadecimal value.
Convert X to uppercase hexadecimal.
Printf outputs the integer returned by the formatted string
Syntax format: int printf (string format, mixed [ARGs]...);
Example
Printf ("% d -- % s -- % x", 72, 72 );
Output result :-
Split and spell string
Explode syntax format: array explode (string separator, string [, int limit])
Implode syntax format: String implode (shring glue, array pieces) Concatenates the array function into a string
String comparison
Strcmp syntax format: int strcmp (string 1, string 2) returns an integer substring.
The strcmp string is used to compare negative values. 1 is smaller than 2. 1 is greater than 2. 0 is equal.
Strlen syntax format: int strlen (string Str); returns an integer from the string length.
Substr syntax format: String substr (string, int start, int [length]);
Obtain some strings. the string is the start character of the string and the number of characters to be stopped. If the character is omitted, the string is to the end. If it is set to a negative number, the string is obtained from the back image.
Strstr string strstr (string haystack, string needle); returns the string from the start to the end of a string. This means that the string of the last segment is obtained from a certain point.
Syntax format: String strrchr (string haystack, string needle)
Strpos syntax format: int strpos (string haystack, string needle, int [offset]); returns false if no value is found when the first position of the string appears.
Strrpos syntax format: int strrpos (string haystack, char needle); returns an integer that returns false if the final position of the string is not found.
String Filling
The str_pad syntax format can be used to protect sensitive information.
Str_pad ($ input, 10); // produces "alien"
Str_pad ($ input, 10, "-=", str_pad_left); // produces "-=-alien"
Str_pad ($ input, 10, "_", str_pad_both); // produces "_ alien ___"
Str_pad ($ input, 6, "___"); // produces "alien _"
Str_pad_left string left Complement
Add the str_pad_right string to the right
Supplement the two ends of the str_pad_both string
String replacement
Str_replace () function replacement
There are three methods
Str_replace ("L", "@", "hello"); // replace
$ Arr2 = array ("% color %", "% title %", "% body % ");
$ Arr3 = array ("red", "hello", "world ");
Echo str_replace ($ arr2, $ arr3, "<font color = % color % Title = % title %> % body % </font> ");
Touch version Method
String Translation
An important replacement function of strtr () is also called string translation.
Strtr can also be called in two ways.
Strtr (string $ STR, string $ from, string $)
$ Arr5 = array ("hello" => "hi", "Hi" => "hello ");
Echo strtr ("Hello is hi", $ arr5 );
Is to translate
Strtr (string $ STR, array $ replace_pairs)
HTML processing
HTML Entity processing
htmlentities (); (specify the conversion mode and character set encoding)
ent_compat (default ): specify double quotation marks for conversion but keep single quotation marks
ent_quotes: both double quotation marks and single quotation marks are converted.
ent_noquotes: both are not converted.
htmlspecialchars (); (convert special symbols such as <> into objects <>)
syntax
$ STR = "
China
";
echo htmlentities ($ Str); // conversion encoding
echo htmlentities ($ STR, ent_quotes, "EUC-JP "); // single quotes and double quotation marks are converted to the character encoding.
processing quotation marks
stripslashes (); (this is the inverse function of addslashes, displaying the characters after transfer)
Ddslashes (); (add \ Display '"\ null (\ 0) before 4 characters)
clear HTML tags
strip_tags (); (clear HTML hypertext characters in a string)
URL Processing
In addition to HTML text processing, the URL address must be processed during web development. Processing URLs mainly include:
parsing URL strings
parse_str (); (Resolving request strings into arrays)
parse_url (); (parse the complete URL into an array)
URL encoding
rawurlencode (); (replace all non-alphanumeric characters with % followed by two hexadecimal characters)
urlencode (); (replace all non-alphanumeric characters with % followed by two hexadecimal characters, and the space with a plus sign)
rawurldecode ();
urldecode (); (parses and restores the URL encoded with % #)
constructs a query string.
http_build_query (); (the request string generated after URL-encoded)
php# .rar