String operation functions

Source: Internet
Author: User
Tags strtok
There are many character string operations in PHP3.0, including the following: (1) echo, print, printf, and sprintf are used to output the character string. 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) string operations in strchr, strlen, strtok, strrchr, strrev, strstr, strtolower, strtoupper, substr, and ucf PHP3.0 have many functions and are important to the following:

(1) echo, print, printf, sprintf

Used to output the string. if there is a variable name in the string, it will be replaced with its value. The last two functions are similar to functions with the same name in C.

 

(2) strchr, strlen, strtok, strrchr, strrev, strstr, strtolower, strtoupper, substr, ucfirst

The string operation function used. some functions with the same name in C have exactly the same meaning. strrev is used to flip a string. strtolower and strtoupper convert strings to lower case and upper case. 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

Function of the same name.

 

(4) explode, implode, join

Array-related functions. 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

Process the white space at the end of the string.

 

(6) htmlspecialchars

Replace special HTML characters with their names, for example, "<" to "<".

 

(7) nl2br

Add"
".

 

(8) AddSlashes, StripSlashes

Add "\" and remove "\" to the string as needed. for some databases, you must add and remove "\" to the characters to be queried before querying.

 

(9) parse_str

Analyze the string of the "name1 = value1 & name2 = value2 &..." type into some variables.

 

For example: parse_str ("a = 1 & B = 2"); generate two variables $ a and $ B, with values 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 & a [] = 2", an array $, 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.