Home > Backend Development > PHP Tutorial > Implementation of the current number of people online on the website_PHP tutorial

Implementation of the current number of people online on the website_PHP tutorial

WBOY
Release: 2016-07-13 17:24:46
Original
993 people have browsed it

Probably the most important component of a website is the number of sites that link to you. This tutorial will show you a simple way to do it using the AltaVista
search engine.
First, we need to prepare the URL to be used in the script. This can be used:
http://www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link%3A&search=Search.
You should know that this is a text version of AltaVista. This saves us a lot of code that needs to parse HTML. Next, we
need the exact URL. We should use rawurlencode() to process the URL to ensure Altavista can handle it correctly.


$url = http://www.php.net;
$url_encoded = rawurlencode($url);
$url_to_check = "http://www.altavista .com/cgi-bin/query?
kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search";
?>
Now we have all the URLs we need. It's time for us to retrieve the URL. This step is done by using the file() function.

$url = http://www.php.net;
$url_encoded = rawurlencode($url);
$url_to_check = "http://www.altavista.com/ cgi-bin/query?
kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search";
$alta_search = file($url_to_check);
?>
Now what we have captured The returned file has been stored in the array $alta_search. We now want to find the text we want in the array. The text we want is "About (.*) pages found. ". (.*) means anything between two words. Moreover, if no one links to our URL, AltaVista will display "AltaVista found no document matching your query.". Since we want to know how many people are linking to our URL, that text will be treated as 0 people linking.



$url = http://www.php.net;
$url_encoded = rawurlencode($url);
$url_to_check =
"http:// www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search";
$alta_search = file($url_to_check);
for ($i = 0 ; $i if(eregi( "About (.*) pages found.", $alta_search[$i])){
$how_many = eregi_replace( "
About (.*) pages found.", "1", $alta_search
[$i]);
}elseif(eregi( "AltaVista found no document matching your query.", $alta_search
[$i])){
$how_many = 0;
}
}
?>
In order to use the above processing results, you can add this code to print our Find results:
echo "$how_many people are linking to $url";

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532118.htmlTechArticleProbably the most important component of a website is the number of sites that link to you. This tutorial will show you a simple way to do this using the AltaVista search engine. First of all, I...
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