This article describes a simple way for PHP to determine whether a string contains another string. Share to everyone for your reference, as follows:
When using PHP to determine if a string contains a simple substring, we usually use Strpos () or stristr (), but it happens that if the position of the 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, there is a stupid way, but more useful, both in English, punctuation is applicable.
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);
More readers interested in PHP related content can view this site topic: "PHP Operations Office Document Tips summary (including word,excel,access,ppt)", "PHP date and Time usage summary", "PHP Object-oriented Programming tutorial", "PHP string (string) Usage summary, "Getting Started with Php+mysql database operation" and "PHP common database Operation Skills Summary"
I hope this article is helpful to you in PHP programming.
The above describes the PHP simple to determine whether the string contains another string, including the contents of the content, I hope the PHP tutorial interested in a friend helpful.