How to use string functions in PHP

Source: Internet
Author: User
Tags strtok
There are many string operations in php. The following are important: (1) the first two functions of echo, print, printf, and sprintf are output strings. if there is a variable name in the string, it is replaced with its value. the last two functions are similar to c functions with the same name. (2) There are many string operations in strchr, strlen, strtok, strrchr, strrev, strstr php, and the following are important:

(1) echo, print, printf, sprintf
The first two functions are output strings. if there is a variable name in the string, it is replaced with its value.
The last two functions are similar to c functions with the same name.

(2) strchr, strlen, strtok, strrchr, strrev, strstr, strtolower,
Strtoupper, substr, ucfirst
These are commonly used string operation functions, and some of them are exactly the same as the functions of the same name in c.
Strrev is used to flip a string.
The meaning of strtolower and strtoupper should not be explained.
Ucfirst converts the first character of a string to uppercase.
Substr is a substring of the returned string. its usage is substr (string, header, length ).
The header position is counted from 0. if it is a negative number, it indicates the forward number from the tail.

(3) chr, ord
Similar to c functions with the same name.

(4) explode, implode, join
These are functions related to arrays.
Explode (string, delimiter) returns an array generated when the string is split.
Implode (array, delimiter) returns a string that inserts a delimiter into each element of the array.
Join and implode have the same meaning.

(5) chop
Removes the white space at the end of the string.

(6) htmlspecialchars
Replace the special html characters in the string with their names, for example, "<" to "<".

(7) nl2br
Add"
".

(8) addslashes, stripslashes
Add "\" to the string to be used for database query, and remove "\".

(9) parse_str
Set "name1 = value1! Amp; name2 = value2! The type of string is analyzed into some variables.
For example:
Parse_str ("a = 1! Amp; B = 2 ");
Generate two variables, $ a and $ B. The values are 1, 2, respectively.
If two pairs of names/values have the same name, the latter value overwrites the previous one.
If the two pairs have "[]" at the end, for example, "a [] = 1! Amp; a [] = 2 ", an array $ a is generated, and the two elements are respectively 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.