首页 > php开发 > php 判断字符串包含指定字符

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

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

//实例一,代码如下: 

<?php
$string="i am abc"; 
if (ereg ("www.phprm.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.phprm.com>test</a>", $string);


文章网址:http://www.phprm.com/develop/fs4293.html

随意转载^^但请附上教程地址。

标签:php字符串 指定字符

相关文章

发表留言