Introduction: This is a detailed page for using js to call PHP in HTML. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 323141 'rolling = 'no'>
We often see a lot of website statisticsCodeThey are all displayed in the form of JS calls. Let's take a look at how the instance works.
<? PHP
$ Countfile = "num.txt ";
// Define that the file written by the counter is count.txt under the current directory. Then, we should test whether the file can be opened.
If ($ fp = fopen ($ countfile, "R +") = false) {// open the file in read/write mode. If the file cannot be opened, exit.
Printf ("opening file % s failed! ", $ Countfile );
Exit;
}
Else
{
// If the file can be opened normally, the data in the file will be read, assuming 1
$ COUNT = fread ($ FP, 10 );
// Read 10-Bit Data
$ COUNT = $ count + 1;
Fclose ($ FP );
// Close the current file
$ Fp = fopen ($ countfile, "W + ");
// Open the file in overwrite Mode
Fwrite ($ FP, $ count );
// Write new data after 1
Fclose ($ FP );
// Close the file
Echo 'document. Write ("'. $ count.'") n ';
// Output data in Javascript format
}
?>
In the HTML file, JS calls the method.
<HTML>
<Head>
<Title> example of page separation counter </title>
</Head>
<Body>
Hello, you are the first
<Script language = "JavaScript" src = "filecount. php">
// Pay attention to the server and directory path of the PHP counter when referencing.
</SCRIPT>
Visitor
</Body>
</Html>
More articles about "using js to call PHP content in HTML"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/323141.html pageno: 16.