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

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

请先在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>


相关文章
|
18天前
|
设计模式 PHP
php设计模式--装饰模式(七)装饰模式完成文章编辑
php设计模式--装饰模式(七)装饰模式完成文章编辑
10 0
|
1月前
|
Java API PHP
多多关键字API php java Python
多多关键字API接口广泛应用于商家进行市场分析、竞品分析、关键词优化等场景。商家可以通过分析关键词数据,了解用户需求,制定针对性的营销策略,提高产品的曝光率和转化率。