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.
我知道我可以用它strpos来查找第一次出现的字符串。但是是否有可能找到不是字母字符或数字的字符的第一次出现。
strpos
例如:
strpos2('hello world') => 5
strpos2('hi!you') => 2
尝试preg_match
preg_match
$string = "hi!you"; preg_match('/[\W]+/', $string, $match, PREG_OFFSET_CAPTURE); print_r($match);
这里 $match 将返回第一个匹配的非字母字符的位置