积木首页 | 500多种网页特效 | 函数手册 | 广播电台 | 高清晰图片素材 | 服务器合租 | 万年历 | 网友最新浏览记录
程序开发 网页设计 搜索引擎 特效代码 操作系统 防范病毒 黑客技术 图形图象 电脑硬件 网络技术 服 务 器 数 据 库 网文精粹
您的位置:积木首页 >> 程序开发频道 >> PHP >> 正文:
标题:正则表达式例子:在一个字符串中查找另一个字符串
时间:2006-12-13 来源:不详 浏览数:
<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>
(责任编辑:笑虎)
关于本站 | 广告服务 | 联系我们 | 版权申明 | 强强联盟 | 投稿热线 | 网站地图 | 申请链接
Copyright ©2005-2006 Gimoo.net All rights reserved. 积木网 版权所有
E-mail:gimoohr@gmail.com 京ICP备05050695号