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>

相关文章

Could not load type System.ServiceModel.Activation.HttpModule解决办法

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.Service...

PHP中通过ADO调用Access数据库的方法测试不通过

我看了那篇《怎样在PHP中通过ADO调用Asscess数据库和COM程序》文章后,马上作了测试,结果失败了。伤心是不是。  怎么办?我只好去PHP官方网站求助,皇天不负有心人,...

PHP防范SQL注入的具体方法详解(测试通过)

一个优秀的PHP程序员除了要能顺利的编写代码,还需要具备使程序处于安全环境下的能力。今天我们要向大家讲解的是有关PHP防范SQL注入的相关方法。 说到网站安全就不得不提到SQL注入(SQ...

PHP strip_tags保留多个HTML标签的方法

本文介绍了PHP strip_tags函数保留多个HTML标签的方法,可以使用第二个参数来设置不需要删除的标签,主要涉及到strip_tags的第二个参数 strip_tags 函数 语...

PHP针对常规模板引擎中与CSS/JSON冲突的解决方法

本文实例讲述了PHP针对常规模板引擎中与CSS/JSON冲突的解决方法,有一定的实用价值,具体分析如下: 本文主要针对对象为Smarty与Dwoo 在Smarty中经常会出现和CSS/J...