Home > Backend Development > PHP Tutorial > 在HTML中利用js调用php的内容_PHP

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

WBOY
Release: 2016-06-01 12:25:03
Original
925 people have browsed it

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

$countfile = "num.txt";
//定义计数器写入的文件是当前目录下count.txt,然后我们应当测试该文件能否打开

if (($fp = fopen($countfile, "r+")) == false) { //用读写模式打开文件,若不能打开就退出
printf ("打开文件 %s 失败!",$countfile);
exit;
}
else
{
//如果文件能够正常打开,就读入文件中的数据,假设是1
$count = fread ($fp,10);
//读取10位数据
$count = $count + 1;
fclose ($fp);
//关闭当前文件
$fp = fopen($countfile, "w+");
//以覆盖模式打开文件
fwrite ($fp,$count);
//写入加1后的新数据
fclose ($fp);
//并关闭文件

    echo 'document.write("'.$count.'")n';
    //用javascript形式输出数据

}
?>
在html文件里面js调用方法。


页面分离计数器范例


您好,您是第

位访客

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template