作者:狗血饭团联_367 | 来源:互联网 | 2018-07-16 14:58
下面是利用正则表达式来判断字符串包含指定字符的php代码,主要用到了ereg函数来征
//实例一
代码如下 |
|
$string="i am abc";
if (ereg ("www.111cn.net", $string)) echo "'abc' is true ";
if (ereg ("^abc", $string)) echo "'^abc' is true ";
if (ereg ("abc$", $string)) echo "'abc$' is true"; |
//实例二
代码如下 |
|
$string = "this is a test. that is another test.";
echo ereg_replace (" is", " was", $string)."";
echo ereg_replace (" is", " is", $string)." ";
echo ereg_replace ("test", "test", $string); |