·您的位置: 首页 » 资源教程 » 编程开发 » PHP » 正则表达式例子:在一个字符串中查找另一个字符串

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

类别: PHP教程  评论数:0 总得分:0
<html>
<head><title>正则表达式</title></head>
<body>
<a href="./">返回列表</a><br>
<form action="<?echo $PHP_SELF;?>" method="post">
在<input type="text" name="string" value="<?echo $string;?>">中查找<input type="text" name="query" value="<?echo $query;?>"><br>
<input type="radio" name="where" value="" <?if(!isset($where) or $where=="") echo "checked";?>>第二个字符串可以在第一个字符串的任何位置<br>
<input type="radio" name="where" value="^" <?if(isset($where) and $where=="^") echo "checked";?>>第一个字符串以第二个字符串开始<br>
<input type="radio" name="where" value="$" <?if(isset($where) and $where=="$") echo "checked";?>>第一个字符串以第二个字符串结束<br>
<input type="checkbox" name="case" value="case" <?if(isset($case)) echo "checked";?>>区分大小写<br>
<input type="submit" value="查询">
</form>
<?
if(isset($string) and isset($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>




-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1