加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

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

发布时间:2020-05-28 23:39:56 所属栏目:PHP 来源:互联网
导读:在php下实现从指定的字符串中搜索字符串

<a href="./">返回列表

<form action="<?echo $PHP_SELF;?>" method="post">
在<input type="text" name="string" value="<?echo $string;?>">中查找<input type="text" name="query" value="<?echo $query;?>">

<input type="radio" name="where" value="" <?if(!isset($where) or $where=="") echo "checked";?>>第二个字符串可以在第一个字符串的任何位置

<input type="radio" name="where" value="^" <?if(isset($where) and $where=="^") echo "checked";?>>第一个字符串以第二个字符串开始

<input type="radio" name="where" value="$" <?if(isset($where) and $where=="$") echo "checked";?>>第一个字符串以第二个字符串结束

<input type="checkbox" name="case" value="case" <?if(isset($case)) echo "checked";?>>区分大小写

<input type="submit" value="查询">

<?
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 "未找到!";
  }
}
?>

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读