下面是利用正则表达式来判断字符串包含指定字符的php代码,主要用到了ereg函数来验证:
-
- ?
- $string="i am abc";
- if (ereg ("www.phpfensi.com", $string)) echo "'abc' is true <p>";
- if (ereg ("^abc", $string)) echo "'^abc' is true <p>";
- if (ereg ("abc$", $string)) echo "'abc$' is true";
-
-
-
- $string = "this is a test. that is another test.";
- echo ereg_replace (" is", " was", $string)."<p>";
- echo ereg_replace (" is", "<b> is</b>", $string)."<p>";
- echo ereg_replace ("test", "<a href=http://www.phpfensi.com>test</a>", $string);
|