How to output PHP results to a non-PHP page _php tutorial

Source: Internet
Author: User
The problem is that when I've implemented my own statistics count, I want to use its output in my PHP-capable pages, so what should I do? The main solution is to output a JavaScript script. This is useful, for example, to implement dynamic news, ad polling, of course, here is how to put a program's download count output to a non-PHP page.

First let's imagine: I already have a program to download the count file on my website, such as. /count/download.db.
 
The file format is:
index | filename Hint | link | count
Note that the "|" is used here. Line separation. I am using a text file for processing. There may be a row of data for:
file1| test file 1|. /download/file1.zip|10
As you can see, the number of downloads may have been 10 times. Now I want to output this 10 times to other pages.
 
First step: Write JavaScript scripts
Very simple:

Isn't it! SRC refers to the output of the script program, "?" The arguments to the incoming script are followed. So what data should the output.php output
To be executed? You should output JavaScript statements, such as document.write (). This way, the browser will put the output.php
The output of a JavaScript program is treated as if it were written directly, except that the script is from somewhere else.
To get.
 
Well, to know what should be output, you can write a PHP program.
 
Step Two: Output results

$fp=fopen (".. /count/download.db "," R ");
$flag=false;
while (!feof ($FP))
{
$line=fgets ($FP, 256);
List ($index, $title, $count) =split ("|", $line);
if (Strtolower ($index) ==strtolower ($id))
{
$flag=true;
Break
}
}
Fclose ($FP);
if ($flag)
{
echo "document.write ($count);";
}
Else
echo "document.write" ("Not Found"); ";
?>
This code is also very simple, but there are a few points to explain. Open a file first. $flag indicates whether the file record for the specified index is found.
First set to False. It is again a loop, provided the file is not finished.
 
Then the loop body: Take out a line of text, the length is best long point. Split the fields to "|" As a separator. Note that the split letter used
Number is a regular expression, "|" is a special symbol used for the "" number. They are then placed in the corresponding variable. What we really care about here is
$index and $count. Compares the input parameter $id with the fetched index ($INDEX), and if it is equal, sets the find flag to True,
Exits the loop. Otherwise, the next row of data is found.
 
At the end, close the file and output the appropriate JavaScript script based on whether the flag is found.
 
For the use of $id, PHP automatically will be called at the URL of the id=xxx is processed, can be used directly. You can also use
$http_get_vars[id].



http://www.bkjia.com/PHPjc/445206.html www.bkjia.com true http://www.bkjia.com/PHPjc/445206.html techarticle the problem is that when I've implemented my own statistics count, I want to use its output in my PHP-capable pages, so what should I do? The main solution is to output a ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.