1, Addslashes
Addslasehes ($string) to compile and escape a string
Application scenario: can prevent SQL injection (of course, it is not entirely possible, we can use PDO for preprocessing and then SQL injection, security can not only one way to prevent the occurrence of things)
2, Echo, Print,printf,number_format
1) echo is a language structure, not a function, no return value, can output multiple values
For Example:echo $a, $b
Scenario: outputting Some strings
2) Print is a function, it has only one parameter, has a return value, cannot output object and array
Application scenario: output some parameter values
3) Print_r () is a function that has a return value that can output objects and arrays
Application Scenario: Print some arrays or objects
4) Var_dump is a function that has a return value
Scenario: the ability to return the type of data, print all values
5) printf () is a function that has a return value, formatted output
Application scenario: Parameter stitching of API interface
For example:
$str = ' string '; $num = 1;
sprintf ("$s is a string, $u is int", $STR, $num);
can also format floating-point numbers, which is the ceil principle, rounding
sprintf ('%.2f ', 23.453) 23.45
6) Number_format (num,int= to keep the decimal digits, if not write will be rounded) convert number to currency format
3, Trim,rtrim,ltrim
Remove whitespace and specified characters from the string
Trim ($string, ' str ') removes the specified character from the entire string, and if not, the default is to remove the space, etc.
LTrim () ibid. remove left, RTrim () ibid. Remove right
Application scenario: Remove the left and right space when the user sets the password
4, Implode,join
Convert an array to a string
Application scenarios: For example, if you have a user's information to be displayed on the front end, then the backend returns an array, then you can use implode (', ', $arr)
5, Explode,str_split
Splits a string into an array
Application scenarios: For example, front-end to backend a 1,simengphp you want or simengphp this string, then you can use
Explode (', ', $arr) [1]
6, SUBSTR,STRSTR,STRRCHR
1) Intercept function of substr string
Scenario: I want to get the first few strings
substr ($STR, 0,n) disadvantage, if it is a Chinese character will cause truncation garbled
Mb_substr ($str, 0,n, ' encode ') This can be intercepted by specifying a character encoding
2) Strstr the position of a character and returns the value of the second half of the character in the string
Strstr ($str, '. ')
3) STRRCHR ()
Application scenario: $str = ' uploads/a.b.php '; Echo strrchr ($str, '. '); Output. PHP This is a classic face question
7, Str_replace,str_ireplace, Substr_replace
1) str_replace (search,res, $str) Replace something you want.
Scenario: Replace a value from a word that a user passes over
2) Substr_replace ($STR, Res,0,n)
Application Scenario: Hide the number of middle numbers in the phone number
$str = ' 18522713541 ';
Echo Substr_replace ($str, ", 3,3);//18513541
8, Strlen,strpos,stripos,strrpos,strripos
1) strlen Gets the length of the string
Scenario: Using SUBSTR to calculate the length of a user's intercept string
2) Strpos a character out of the first time, and returns the number of digits (case-sensitive) of the string.
Application scenario: Back to the front end of a full path time, to determine whether to include HTTP, if included is not splicing, does not include the stitching
Stripos Ditto case-insensitive
3) Strrpos returns the position of the last occurrence of a character in a string
Strripos, not missing the case
9, Nl2br,htmlspecialchars (), Htmlspecialchars_decode (), Strip_tag ()
1) nl2br convert N to BR
2) Htmlspecialchars () turn some special characters into HTML entities
Application scenario: The general Rich Text editor passes all the special characters, then you save the database directly to the HTML to save in.
3) Strip_tags ($STR, [allows_tags]) Remove the HTML code, Allows_tags is allowed to exist which tags
Application Scenario: Filter out some HTML code and then intercept the presentation to the introductory place
10, Lcfirst,ucfirst,ucworlds,strtolower,strtoupper
1) lcfirst () lowercase the first letter of a character
2) Ucfirst () capitalizes the first character of a character
3) Unworlds () converts the first letter of each word in a string to uppercase
4) Strtolower () turn all characters into lowercase
5) Strtoupper () turn all characters into uppercase
12, Str_repeat,str_pad
1) str_repeat (x,num) repeats a character how many times
Application Scenario: Our news portal introduction is not open, need to use ... Instead, then we can use this repetition and then show
2) Str_pad ($str, ' X ', 10) fills the specified character string to the specified length
Application scenario: For example, we have a requirement to unify some fields into a string of the same length, and then transfer to the background processing, you can use this
13, Sha1,md5,hex2bin,bin2hex
1) SHA1 and MD5 cryptographic functions
2) Hex2bin converts a character to 22 binary with 16, bin2hex the opposite
Application scenario: The above are the transmission parameters for encryption and verification of common cryptographic functions, including one-way and two-way plus decryption
14, Pase_str,pase_url,pathinfo,http_build_query
1) pase_str ($STR, $out) converts a string into an array $out [XX]
Scenario: Route resolution get parameter names and parameter values
2) Pase_url ($url) parsing a URL, returning header information, host domain name, etc.
Scenario: Get the host name of the current URL and the domain name, etc.
3) PathInfo () returns the path information for the file
Scenario: Get the file extension pathinfo () [extension]
4) Http_build_query ($arr, [with a word linked])
Scenario: Converting an array to a character in a URL parameter format
You should be in this position. Learn PHP (1)