PHP String function classification, phpstring function_PHP tutorial

WBOY
Release: 2016-07-13 09:56:15
Original
892 people have browsed it

PHP String function classification, phpstring function

1. Find character position function:

strpos ($str,search,[int]): Find the first position of search in $str starting from int;

stripos ($str,search,[int]): The function returns the position of the first occurrence of a string in another string. This function is not case sensitive

strrpos ($str,search,[int]): Find the last occurrence of search in $str starting from int

2. Extract sub-character function (double bytes)

submit ($str,int start[,int length]): Extract [length-length string] starting from the strat position in $str.

strstr ($str1,$str2): Search $str2 from $str1 (the first position) and intercept the string starting from it to the end; if not, return FALSE.

stristr() has the same function as strstr, except that it is not case-sensitive.

strrchr() returns from the last character searched; use: to get the file name in the path

3. Replace string

str_replace (search,replace,$str): Find search from $str and replace

with replace

str_irreplace (search,replace,$str): Not case sensitive

strtr ($str,search,replace): replace in this function cannot be "";

substr_replace ($str,$rep,$start[,length]) $str original string, $rep new string after replacement, $start starting position, $length replacement length, this item Optional

4. Character length

int strlen($str)

5. Comparison character function

strcmp ($str1,$str2): $str1>=<$str2 are positive 1, 0, -1 respectively (string comparison)

strcasecmp() Same as above (not case sensitive)

strnatcmp("4","14") compares strings in natural order

strnatcasecmp() Same as above, (case sensitive)

6. Split into array functions

str_split ($str,len): Split $str according to the length of len and return the array

split (search,$str[,int]): Split $str according to the search character and return the array int how many times it is divided, and the rest will not be divided

explode (search,$str[,int])

7. Remove spaces: ltrim, rtrim, trim

8. Add space function

chunk_split ($str,2); Press 2 characters into the $str character to add a space;

9, chr, ord -- return the specified character or ascii

10. Functions related to HTML code

nl2br(): Convert n to
.

strip_tags($str[,'

']): Remove HTML and PHP tags. All HTML and PHP code in $str will be removed, and the optional parameters are html and PHP codes that will retain the code written by the optional parameters. For example: echo strip_tags($text, '

');

htmlspecialchars($str[, parameter]): The normal output of the page HTML code parameters is the conversion method

11. Character case conversion function

strtolower($str) converts the string to lowercase

strtoupper($str) Convert string to uppercase

ucfirst($str) Converts the first character of the function to uppercase

ucwords($str) Converts the first letter of each word to uppercase

12. Database related functions

Addslashes($str): Convert single quotes ('), double quotes ("), backslashes () and NUL strings in str to ',",\.

Magic_quotes_gpc = On Automatically escape the content of get post cookie

Get_magic_quotes_gpc() Check whether magic_quotes_gpc is turned on

When magic_quotes_gpc=On, the function get_magic_quotes_gpc() will return 1

When magic_quotes_gpc=Off, the function get_magic_quotes_gpc() will return 0

Stripslashes() removes backslashes from strings

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/989817.htmlTechArticlePHP String function classification, phpstring function 1. Find character position function: strpos($str,search,[int] ): Find the first position of search in $str starting from int; stripos($str,search,[int]...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!