Check if a String Contains Multiple Words in PHP
Check if a string contains multiple words:
function str_contains_multiple_words($string, $array_of_words) { if (!$array_of_words) return false; $i = 0; foreach ($array_of_words as $words) { if (strpos($string, $words) !== FALSE) $i++; } return ($i == count($array_of_words)) ? true : false; } |
Example usage:
if(str_contains_multiple_words("this is a string", array("is", "string"))) { echo 'Words "is" and "string" found!'; } echo 'Words "is" and "string" not found!'; } |
More Related Posts
- [2016/06/04] Check if a Number is Multiple of Anoth...
- [2016/06/07] How to Get File Extension in PHP
- [2016/05/20] Turn Off Expose_PHP (Hide X-Powered-By...
- [2016/05/26] How to Increase PHP Memory Limit
- [2016/05/25] Disable PHP Notice: Undefined variable...
- [2016/05/27] PHP Domain Parser: Domain\URL Parser P...
- [2016/05/19] Validate Value as Integer in PHP
- [2016/05/19] Remove Non-Alphanumeric Characters fro...