How to use String functions in PHP
Last Update:2017-02-28
Source: Internet
Author: User
function | string PHP string manipulation functions are more, important are the following:
(1) echo,print,printf,sprintf
the first two functions are output strings. If a variable name is substituted in the string, it is replaced with its value.
two functions are similar to C's with the same name function.
(2) Strchr,strlen,strtok,strrchr,strrev,strstr,strtolower,
Strtoupper,substr,ucfirst
these are commonly used string manipulation functions, some of which have exactly the same meaning as the functions of the same name in C.
Strrev is to flip a string.
The meaning of
strtolower and strtoupper should not be explained.
Ucfirst The first character of the string into uppercase.
substr is a substring of the return string, using the following: substr (string, header, length).
The
head position is from 0. If it's a negative number, it's from the tail forward.
(3) Chr,ord
is similar to C with a function of the same name.
(4) Explode,implode,join
These are the functions that are related to the array.
explode (string, delimiter) returns an array of strings that are produced by separating the string from the separator.
implode (array, delimiter) returns a string that inserts a delimiter between the elements of an array.
join has the same meaning as implode.
(5) Chop
removes whitespace from the tail of the string.
(6) Htmlspecialchars
Replace the HTML special characters in the string with their names, for example, "<" becomes "<".
(7) nl2br
adds "<BR>" to the front of each carriage return in the string.
(8) addslashes,stripslashes
adds and removes "\" to characters in the string that need to be added "\" to the database query.
(9) Parse_str
the string of "Name1=value1&name2=value2& ..." into some variables.
For example:
parse_str ("a=1&b=2");
generates $a and $b two variables, the values are 1,2 respectively.
If there are two names that are part of the same name/value, then the value of the last one overwrites the previous one.
if the names of both pairs have "[]", such as "a[]=1&a[]=2", the array $a is generated, two elements are 1, 2