前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >原生php实现统计关键字在文章中出现的次数

原生php实现统计关键字在文章中出现的次数

作者头像
贵哥的编程之路
发布2022-05-06 12:44:00
4550
发布2022-05-06 12:44:00
举报
文章被收录于专栏:用户7873631的专栏

请先在text.txt文件里面写东西.

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  
<style type="text/css">
  #center{
    width:300px; 
    border:1px solid #ccc;
    height:auto;
    margin:0 auto;
    text-align:center;
    color:#ff6666;
    font-weight:normal;
  }
  #content p{
  width:300px;
  text-indent:20px;
  border:1px solid #ccc;
  margin-bottom:3px;
  padding:5px 5px 5px 5px;
  font-weight:normal;
  }
  #showTime{
  color:#99cc66;
  }
  #area{
  margin-bottom:10px;
  }
  #input{
  margin-top:10px;
  }
  #text{
  width:300px;
  height:auto;
  line-height:30px;
  border:1px solid #ccc;
  font-weight:normal;
  font-size:14px;
  text-indent:20px;
  color:#339933;
  padding-top:10px;
  padding-bottom:10px;
  padding-left:10px;
  padding-right:10px;
  }
</style>
</head>
 <body>
  <div id="header">统计关键字在文章中出现的次数</div>
  <div id="content">
    <center>请输入查询关键字:</center>
    <center>
      <form action="cyg.php" method="post">
        <input type='text' value='' name='str' size=15><br>
        <input type="submit" value="查&nbsp;询" id='input'>
      </form>
    <div id='text'>
    <?php echo $text=file_get_contents('text.txt');?>
    </div>
    </center>
    <?php
    if(!empty($_POST['str'])){
      $str = $_POST['str'];
      echo "<script>alert('".$str."关键字出现的次数为:".substr_count($text,$str)."');</script>";
    }
    ?>
  </div>
</body>
</html>
在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-03-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档