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中JSON的使用方法

从5.2版本开始,PHP原生提供json_encode()和json_decode()函数,前者用于编码,后者用于解码。 json_encode()   &...

php创建和删除目录函数介绍和递归删除目录函数分享

mkdir() — 新建目录 复制代码 代码如下: – 语法:bool mkdir (string pathname [,int mode]) – 尝试新建一个由 pathname 指定...

PHP中func_get_args(),func_get_arg(),func_num_args()的区别

复制代码 代码如下:<?php     function jb51(){     &nbs...

php数据结构之顺序链表与链式线性表示例

本文实例讲述了php数据结构之顺序链表与链式线性表。分享给大家供大家参考,具体如下: 链表操作 1、     InitList(L):初始化链表...

可兼容php5与php7的cURL文件上传功能实例分析

本文实例讲述了可兼容php5与php7的cURL文件上传功能。分享给大家供大家参考,具体如下: 为啥要写这个示例 最近修改一个项目,需要通过cURL上传文件。 记得之前做过类似实现的,于...