Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
根据文档,preg_grep在数组中搜索正则表达式。
preg_grep
是否有任何函数可以获取正则表达式数组并将它们与字符串进行比较?
例如:
$arr = array("^foo-", "-bar$"); magic_function($arr,"Just a string"); // returns false magic_function($arr,"foo-"); // returns true
没有内置函数可以执行此操作,但您可以轻松构建自己的:
function magic_function($arr,$str) { foreach($arr as $regex) { if( preg_match($regex,$str)) return true; } return false; }