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

举报
陈业贵 发表于 2022/03/29 01:39:42 2022/03/29
【摘要】 请先在text.txt文件里面写东西. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF...

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

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

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

在这里插入图片描述

文章来源: blog.csdn.net,作者:贵哥的编程之路(热爱分享),版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/qq_37805832/article/details/123806633

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。