Created
May 16, 2015 18:30
-
-
Save saltun/6b2f1e8a9971dbcb592c to your computer and use it in GitHub Desktop.
PHP strpos in array function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Savaş Can ALTUN <[email protected]> | |
* @link http://savascanaltun.com.tr | |
* PHP strpos function in array | |
*/ | |
function strposa($text, $finds, $offset=0) { | |
if(!is_array($finds)) $finds = array($finds); | |
foreach($finds as $query) { | |
if(strpos($text, $query, $offset) !== false) return true; | |
} | |
return false; | |
} | |
$text="My favorite language PHP"; | |
$finds=array("asp","php","python"); | |
/** | |
* Text search keywords | |
* @return true|false | |
*/ | |
var_dump(strposa($text, $finds)); // false | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment