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通过iconv将字符串从GBK转换为UTF8字符集

1. iconv()介绍 iconv函数可以将一种已知的字符集文件转换成另一种已知的字符集文件。例如:从GB2312转换为UTF-8。 iconv函数在php5中内置,GB字符集默认打开...

php中的实现trim函数代码

去掉前后的空格.  假设有一个字符串" ddd dd d ",经过Trim()之后成为"ddd dd d".&nbs...

php专用数组排序类ArraySortUtil用法实例

本文实例讲述了php专用数组排序类ArraySortUtil用法。分享给大家供大家参考。具体如下: ** * ArraySortUtil is a array sort utili...

ASP和PHP实现生成网站快捷方式并下载到桌面的方法

在网站上设置“加入收藏、设为首页”等按钮是一般网站都会干的事儿,但是有的网站还有“放到桌面”这样的功能设置。下面即生成快捷方式并下载到桌面的php实现代码,摘录修改于网络,仅作参考 ph...

php让图片可以下载的代码第1/2页

// 文件目录 define(‘DL_DIR', ‘temp/'); // 常见扩展名所对应的MIME类型 $MIMETypes = array( ‘ez' => ‘applica...