Home>Article>Backend Development> Whether the php string contains a certain string

Whether the php string contains a certain string

(*-*)浩
(*-*)浩 Original
2019-09-07 13:15:09 6525browse

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!

Statement:
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