The example in this article describes how PHP simply determines whether a string contains another string. Share it with everyone for your reference, the details are as follows:
When using PHP to determine whether a string contains a simple substring, we usually use the two functions strpos() or stristr(), but... If the position of this string is at index 0, that is, at the beginning of the string to be matched, there will be a problem.
Of course we still have a solution. Here is a stupid solution, but it is easier to use. It applies to both Chinese and English punctuation marks.
The code is as follows:
function checkStr($str,$target) { $tmpArr = explode($str,$target); //print_r($tmpArr); if(count($tmpArr)>1)return true; else return false; } $result = checkStr("sdfg","bsdfsldkfj"); var_dump($result);
Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP Office Document Skills (Including Word, Excel, Access, PPT)", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php+mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope that what this article has said will be helpful Everyone PHP programming helps.
The above introduces the method of PHP to simply determine whether a string contains another string, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.