php在字符串中查找另一个字符串

yipeiwu_com6年前PHP代码库
<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>

相关文章

PHP Directory 函数的详解

预定义常量: DIRECTORY_SEPARATOR (string) :目录分隔符 PATH_SEPARATOR (string) :路径分隔符 bool chdir ( string...

Php 构造函数construct的前下划线是双的_

定义和用法 __construct() 函数创建一个新的 SimpleXMLElement 对象。 如果成功,则该函数返回一个对象。如果失败,则返回 false。 语法__constr...

php 获取可变函数参数的函数

func_num_args() 返回传递给该函数参数的个数 func_get_arg($arg_num) 取得指定位置的参数值,$arg_num位置index从0开始n-1。 func_...

PHP微信支付结果通知与回调策略分析

本文实例讲述了PHP微信支付结果通知与回调策略。分享给大家供大家参考,具体如下: 支付完成后,微信会把相关支付结果和用户信息发送给商户,商户需要接收处理,并返回应答。 对后台通知交互时,...

php visitFile()遍历指定文件夹函数

注:visitFile()有少量修改 复制代码 代码如下: <? // 查看指定文件夹的文件 $fileList = array(); function visitFile($pa...