首页 > 开发 > PHP > 正文

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

2024-05-04 21:58:28
字体:大 中 小
来源:转载
供稿:网友

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

  1. //实例一,代码如下: 
  2. ​ 
  3.     $string="i am abc"; 
  4.     if (ereg ("www.Vevb.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.Vevb.com>test</a>", $string);  

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表