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

yipeiwu_com5年前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执行zip与rar解压缩方法实现代码

Zip:PclZip http://www.phpconcept.net/pclzip/index.en.php Rar:PECL rar http://pecl.php.net/pac...

php强制下载文件函数

本文实例为大家分享了php强制下载文件函数,供大家参考,具体内容如下 public function down() { $id = $this->_get('id');...

PHP中防止直接访问或查看或下载config.php文件的方法

或是,PHP的设计本身就避免直接查看文件内容的情况? 从安全角度考虑,这个系统级的文件应该做什么保护措施? 网友完善的答案 经调研,得出以下常用方法: 1 在程序中定义一个标识变量 复制...

PHP实现对数组简单求交集,差集,并集功能示例

PHP实现对数组简单求交集,差集,并集功能示例

本文实例讲述了PHP实现对数组简单求交集,差集,并集功能。分享给大家供大家参考,具体如下: <?php $arr1 = array( '0' => 'zero',...

php实现购物车功能(以大苹果购物网为例)

php实现购物车功能(以大苹果购物网为例)

首先是几个简单的登录页面 <body> <form action="chuli.php" method="post"> <div style="mar...