当前位置: 首页 > 图文教程 > 网络编程 > PHP > php在字符串中查找另一个字符串

PHP
用PHP调用Oracle存储过程的方法
FleaPHP的安全设置方法
PHP cron中的批处理
php 301转向实现代码
PHP面向对象分析设计的经验原则
PHP伪造referer实例代码
什么是phpDocumentor
php下防止单引号,双引号在接受页面转义的设置方法
php横向重复区域显示二法
PHP集成FCK的函数代码
php 三维饼图的实现代码
php不用GD库生成当前时间的PNG格式图象的程序
10条PHP编程习惯助你找工作
PHP网站基础优化方法小结
40个迹象表明你还是PHP菜鸟
PHP EOT定界符的使用详解
php数组总结篇(一)
利用PHP制作简单的内容采集器的原理分析
php之对抗Web扫描器的脚本技巧
PHP在字符串中查找指定字符串并删除的代码

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 108 ::
收藏到网摘: n/a

在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>