>  기사  >  php教程  >  php 判断字符串包含指定字符

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

WBOY
WBOY원래의
2016-06-08 17:26:181282검색

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

<script>ec(2);</script>

//实例一

 代码如下 复制代码
    $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);

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.