当前位置:首页 > PHP教程 > php应用 > 列表

php 判断字符串包含指定字符

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-16 13:33:06 浏览: 评论:0 

下面是利用正则表达式来判断字符串包含指定字符的php代码,主要用到了ereg函数来验证:

  1. //实例一,代码如下: 
  2. ​ 
  3.     $string="i am abc"; 
  4.     if (ereg ("www.phpfensi.com", $string)) echo "'abc' is true <p>";                   
  5.     if (ereg ("^abc", $string)) echo "'^abc' is true <p>";                    
  6.     if (ereg ("abc$", $string)) echo "'abc$' is true";  
  7.  
  8. //实例二,代码如下: 
  9.  
  10.      $string = "this is a test. that is another test."; 
  11.      echo ereg_replace (" is", "  was", $string)."<p>"; 
  12.      echo ereg_replace (" is", "<b> is</b>", $string)."<p>"; 
  13.      echo ereg_replace ("test", "<a href=http://www.phpfensi.com>test</a>", $string);  

Tags: php字符串 指定字符

分享到: