当前位置: 首页 > 图文教程 > 网络编程 > PHP > 正则表达式例子:在一个字符串中查找另一个字符串

PHP
PHP实时显示输出
php生成缩略图的类代码
php相当简单的分页类
smarty section简介与用法分析
php优化及高效提速问题的实现方法
php下实现在指定目录搜索指定类型文件的函数
PHP base64+gzinflate压缩编码和解码代码
脚本安全的本质_PHP+MYSQL
使用eAccelerator加密PHP程序
PHP注释实例技巧
php 友好URL的实现(吐血推荐)
关于DISCUZ不用通行证登陆得内容介绍
不用mod_rewrite直接用php实现伪静态化页面代码
Cannot modify header information错误解决方法
php获取地址栏信息的代码
php email邮箱正则
php preg_match_all结合str_replace替换内容中所有img
PHP中str_replace函数使用小结
Zend studio for eclipse中使php可以调用mysql相关函数的设置方法
php flush类输出缓冲剖析

PHP 中的 正则表达式例子:在一个字符串中查找另一个字符串


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 214 ::
收藏到网摘: n/a

<html>
<head><title>正则表达式</title></head>
<body>
<ahref="./">返回列表</a><br>
<formaction="<?echo$PHP_SELF;?>"method="post">
在<inputtype="text"name="string"value="<?echo$string;?>">中查找<inputtype="text"name="query"value="<?echo$query;?>"><br>
<inputtype="radio"name="where"value=""<?if(!isset($where)or$where=="")echo"checked";?>>第二个字符串可以在第一个字符串的任何位置<br>
<inputtype="radio"name="where"value="^"<?if(isset($where)and$where=="^")echo"checked";?>>第一个字符串以第二个字符串开始<br>
<inputtype="radio"name="where"value="$"<?if(isset($where)and$where=="$")echo"checked";?>>第一个字符串以第二个字符串结束<br>
<inputtype="checkbox"name="case"value="case"<?if(isset($case))echo"checked";?>>区分大小写<br>
<inputtype="submit"value="查询">
</form>
<?
if(isset($string)andisset($query)and$string<>""and$query<>""){
if(isset($case)){
$func="ereg";
}
else{
$func="eregi";
}
switch($where){
case"^":
$query="^".$query;
break;
case"$":
$query.="$";
break;
}
eval("\$found=$func(\"$query\",\"$string\");");
if($found){
echo"找到!";
}
else{
echo"未找到!";
}
}
?>
</body>
</html>