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

PHP
php获取mysql版本的几种方法小结
php下判断数组中是否存在相同的值array_unique
PHP中ADODB类详解
常用的php ADODB使用方法集锦
用phpmyadmin更改mysql5.0登录密码
MySQL修改密码方法总结
使用 MySQL Date/Time 类型
How do I change MySQL timezone?
mysql时区问题
某大型网络公司应聘时的笔试题目附答案
PHP连接access数据库
优化PHP代码的40条建议
php简单静态页生成过程
PHP 5.0对象模型深度探索之属性和方法
PHP 5.0对象模型深度探索之对象复制
php,ajax实现分页
FCKeditor添加自定义按钮
php中用文本文件做数据库的实现方法
PHP详细彻底学习Smarty
php图片验证码代码

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 136 ::
收藏到网摘: 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>