Home  >  Article  >  Backend Development  >  String operation functions_PHP tutorial

String operation functions_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 10:59:31817browse

​ There are many string manipulation functions in PHP3.0, the important ones are the following:
(1)echo,print,printf,sprintf
Used to output a string. If there is a variable name in the string, it will be replaced by its value. The latter two functions are similar to the C functions of the same name.

(2)strchr, strlen, strtok, strrchr, strrev, strstr, strtolower, strtoupper, substr, ucfirst
Some of the string manipulation functions used have exactly the same meaning as the functions of the same name in C. strrev is to flip a string. strtolower and strtoupper are to convert the string into lowercase and uppercase. ucfirst is to change the first character of the string into into uppercase. substr is a substring of the returned string. The usage is: substr (string, head, length). The head position is calculated from 0. If it is a negative number, it means counting forward from the tail.

(3)Chr,Ord
Function with the same name.

(4)explode,implode,join
Functions related to arrays. explode(string, separator) returns an array generated by dividing the string at the separator. implode(array, separator) returns an array formed by inserting separators between each element of the array. string. join has the same meaning as implode.

(5)Chop
Handle whitespace at the end of the string.

(6)htmlspecialchars
Replace HTML special characters with their names, for example "<" becomes "<".

(7)nl2br
Add "
before each carriage return in HTML ".

(8)AddSlashes,StripSlashes
Add "" and remove "" to the string as needed. For some databases, you must add or remove "" from the characters to be queried before you can query.

(9)parse_str
Analyze strings of type "name1=value1&name2=value2&..." into some variables.

For example: parse_str("a=1&b=2"); generates two variables $a and $b, with values ​​1 and 2 respectively. If there are two pairs of names/values ​​with the same name part, the value of the latter one will overwrite the previous one. . If the names of these two pairs have "[]" at the end, such as "a[]=1&a[]=2", then an array $a will be generated, with the two elements being 1 and 2 respectively.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445599.htmlTechArticleThere are many string manipulation functions in PHP3.0, the important ones are the following: (1)echo ,print,printf,sprintf are used to output strings. If there is a variable name in the string, it will be replaced with its value. The last two...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn