preg_match()函数是正则表达式的匹配函数,返回值为1或0;
代码如下:
<?php
$str="This is just a test.";
//preg_match("/要找的字符/,"已知字符串")
echo preg_match("/is/i",$str)."<br>";//其中i标记是声明本次查询对字母的大小写不敏感
echo preg_match("/\bte\b/i",$str)."<br>";//其中\b \b标记是声明只查询以te为完整单词的字符,诸如test单词为字符串的则不会被匹配到
?>
结果如下:
1
0