How to use String functions in PHP

Source: Internet
Author: User
Tags array explode functions join variables return
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&amp ..." 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











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.