Home  >  Article  >  php教程  >  在HTML中利用js调用php的内容

在HTML中利用js调用php的内容

WBOY
WBOYOriginal
2016-06-13 10:38:29723browse

        我们经常会看到很多网站的统计代码都是以js调用的形式显示的,下面我们就来看看那如何实例的吧。

  1. $countfile = "num.txt";//定义计数器写入的文件是当前目录下count.txt,然后我们应当测试该文件能否打开
  2. if (($fp = fopen($countfile, "r ")) == false) { //用读写模式打开文件,若不能打开就退出
  3.         printf ("打开文件 %s 失败!",$countfile);
  4.         exit;
  5. }else{
  6.         $count = fread ($fp,10);//如果文件能够正常打开,就读入文件中的数据,假设是1
  7.         $count = $count 1; //读取10位数据
  8.         fclose ($fp);//关闭当前文件
  9.         $fp = fopen($countfile, "w ");//以覆盖模式打开文件
  10.         fwrite ($fp,$count);//写入加1后的新数据
  11.         fclose ($fp);//并关闭文件
  12.         echo document.write(".$count.")n;//用javascript形式输出数据
  13. }
  14. ?>
  15. 在html文件里面js调用方法。
  16. 页面分离计数器范例
  17. 您好,您是第
  18. 位访客

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn