更新时间:2023-01-22 19:56:05
一个简洁的方式与你的两个数据结构做将是:
A concise way to do it with your two data structures would be:
count( array_intersect( str_split($my_string), $special_chars ) )
这也将告诉你有多少特殊字符的字符串中
That would also tell you how many of the special characters are in the string.
您本来写一个循环为你的角色列表和 strpos
手动探测。
You could otherwise write a loop for your character list and manually probe with strpos
.
最少的努力将是你的特殊字符列表转换为正则表达式charclass将和测试对字符串。
The least effort would be converting your special character list into a regex charclass and testing against the string.