3 回答
TA贡献1847条经验 获得超7个赞
str_replace要快得多。
$find_letters = array('a', 'c', 'd');$string = 'abcdefg';$match = (str_replace($find_letters, '', $string) != $string);
TA贡献1818条经验 获得超7个赞
下面的代码不仅展示了如何做到这一点,而且还将它放在一个易于使用的功能中。它是由“jesda”编写的。(我在网上找到了)
PHP代码:
<?php
/* strpos that takes an array of values to match against a string
* note the stupid argument order (to match strpos)
*/
function strpos_arr($haystack, $needle) {
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $what) {
if(($pos = strpos($haystack, $what))!==false) return $pos;
}
return false;
}
?>
用法:
$needle = array('something','nothing');
$haystack = "This is something";
echo strpos_arr($haystack, $needle); // Will echo True
$haystack = "This isn't anything";
echo strpos_arr($haystack, $needle); // Will echo False
- 3 回答
- 0 关注
- 392 浏览
添加回答
举报