How to use String functions in PHP to _php the basics

Source: Internet
Author: User
Tags explode

How to use the String function in PHP the string manipulation function in PHP is more, the important is 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.
The latter 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 a 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
Similar to C's 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 characters 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
Precede each carriage return in the string with "<BR>".

(8) Addslashes,stripslashes
Add and remove "\" for characters in the string that need to be added "\" to the database query.

(9) Parse_str
Parse the string "Name1=value1&name2=value2&amp ..." into some variables.
For example:
Parse_str ("a=1&b=2");
Generates $a and $b two variables with a value of 1,2.
If there are two names that are part of the same name/value, then the last value overrides the previous one.
If the names of both pairs have "[]", such as "a[]=1&a[]=2", the array $a is generated, and 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.