Home > Backend Development > PHP Tutorial > php判断一个字符串是否含有指定的字符(求高效写法)

php判断一个字符串是否含有指定的字符(求高效写法)

WBOY
Release: 2016-06-23 13:24:38
Original
1093 people have browsed it

php判断一个字符串是否含有指定的字符。例:

$str = "pussssasasasds";

判断$str中是否含有abchjgkoqtvwxyz 任意一个字符 也就说判断str是否包含a或者b或者c或者h或者j等等。不区分大小写。求最高效的写法多谢。。

我自己能想到的就是if else... 感觉太笨了 求一个开阔点的思路 好用的高效的方法


回复讨论(解决方案)

用正则

if(preg_match('/[abchjgkoqtvwxyz]/i', $str)) {  echo '包含';}
Copy after login
Copy after login

用正则

if(preg_match('/[abchjgkoqtvwxyz]/i', $str)) {  echo '包含';}
Copy after login
Copy after login


。。。。对对 感谢 感谢
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template