Home > Article > Backend Development > Summary of string manipulation functions in php
The following editor will bring you a collection of string operation functions based on PHP. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.
1. Find character position function:
strpos($str,search,[int])://查找search在$str中的第一次位置从int开始; strrpos($str,search,[int])://查找search在$str中的最后一次出现的位置从int开始
2. Extract sub-character function (double bytes)
submit($str,int start[,int length])://从$str中strat位置开始提取[length长度的字符串]。 strstr($str1,$str2)://从$str1(第一个的位置)搜索$str2并从它开始截取到结束字符串;若没有则返回FALSE。 stristr()//功能同strstr,只是不区分大小写。 strrchr()//从最后一次搜索到的字符处返回;用处:取路径中文件名
3. Replace string
str_replace(search,replace,$str):从$str中查找search用replace来替换 str_irreplace(search,replace,$str): strtr($str,search,replace):这个函数中replace不能为""; substr_replace($Str,$rep,$start[,length])$str原始字符串,$rep替换后的新字符串,$start起始位置,$length替换的长度,该项可选
4. Query string length
int strlen($str)
5. Comparison character function
int strcmp($str1,$str2):$str1>=d1034dd9eb4af79f77b4b30ad7cf51e0.strip_tags($str[,'e388a4556c0f65e1904146cc1a846bee']): //Remove HTML and PHP tags htmlspecialchars($str[,parameter])://The normal output of the page is the conversion method of HTML code parameters
11. Character case conversion function strtolower($str) Convert the string to lowercase strtoupper($str) Convert the string to uppercase ucfirst($ str) Convert the first character of the function to uppercase ucwords($str) Convert 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 escapes the content of the get post cookie get_magic_quotes_gpc() detects whether magic_quotes_gpcstripslashes() is turned on and removes backslashes in the string
13. Connection functionimplode(str,$arr) concatenates the string array into a string according to the specified characters; the implode() function has an alias function join
The above is the detailed content of Summary of string manipulation functions in php. For more information, please follow other related articles on the PHP Chinese website!