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

PHP
php的curl实现get和post的代码
PHP6 先修班 JSON实例代码
phpMyAdmin2.11.6安装配置方法
常用的php对象类型判断
php 中文处理函数集合
php 缓存函数代码
php查看session内容的函数
php下删除字符串中HTML标签的函数
php xml分析函数代码
PHP Mysql编程之高级技巧
swfupload 多文件上传实现代码
PHP开发中常用的8个小技巧
PHP define函数的使用说明
超级全面的PHP面试题整理集合
php判断字符以及字符串的包含方法属性
PHP中常用数组处理方法实例分析
php array_slice函数的使用以及参数详解
PHP生成HTML静态页面实例代码
php将数据库中的电话号码读取出来并生成图片
PHP通用分页类page.php[仿google分页]

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


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