下面是利用正则表达式来判断字符串包含指定字符的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";
|
//实例二
影缘版商城
率先引入语言包机制,可在1小时内制作出任何语言版本,程序所有应用文字皆引自LANG目录下的语言包文件,独特的套图更换功能,三级物品分类,购物车帖心设计,在国内率先将购物车与商品显示页面完美结合,完善的商品管理,具备上架、下架缺货及特价商品设置功能多多,商城名、消费税、最低购物金额、货币符号、商城货币名称全部后台设定,多级用户考虑,管理员只需要设置用户级别、不同级别用户之返点系统自动判断用户应得返还
下载
| 代码如下 |
复制代码 |
$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);
|