Home > php教程 > PHP源码 > body text

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

WBOY
Release: 2016-06-08 17:26:18
Original
1194 people have browsed it

下面是利用正则表达式来判断字符串包含指定字符的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);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!