i am searchgin for a function in php, or a very lightweight and short/easy way to find out if a set (array) of characters appear in a given array
if(chars_in_string(array("x","d开发者_JS百科","9", "ü"), $anystring) ) do_something()
while x,d,9, ü are just as an example ... hmmm maybe i can solve this with regular expressions?
Just use strpbrk($string, implode(array("x","d","9", "ü"))); :)
function all_chars_in_string($chars,$string) {
foreach($chars as $char) {
if (strpos($string,$char) === false) return false;
}
return true;
}
function any_chars_in_string($chars,$string) {
foreach($chars as $char) {
if (strpos($string,$char) !== false) return true;
}
return false;
}
Looking if any char is in string
function anyCharInString($chars,$string) {
foreach($chars as $chr)
if (strpos($string,$chr) !== false) return true;
return false;
}
Look if all chars are in the string
function allCharsInString($chars,$string) {
foreach($chars as $chr)
if (strpos($string,$chr) === false) return false;
return true;
}
EDIT: I'm to slow.
精彩评论