Home>Article>Backend Development> Whether the php string contains a certain string
When writing a program, you often need to process strings. The most basic thing is to search for strings. To detect whether a string contains a specified string in PHP, you can use the following function
strpos(string,find[,start]);
string: required. Specifies the string to search for.
find: required. Specifies the characters to search for.
start: Optional. Specifies the location from which to start the search.
Example(Recommended learning:PHP programming from entry to proficiency)
explode
Use explode to judge. The PHP judgment string contains the following code:
function checkstr($str){ $needle ='a';//判断是否包含a这个字符 $tmparray = explode($needle,$str); if(count($tmparray)>1){ return true; } else{ return false; } }
The above is the detailed content of Whether the php string contains a certain string. For more information, please follow other related articles on the PHP Chinese website!