PHP Short-Address conversion implementation method, PHP conversion
In this paper, the implementation method of PHP short-address conversion is described. Share to everyone for your reference. The specific analysis is as follows:
From yesterday afternoon to now overturned one after another information storage scheme, from MySQL to add the memory unrestricted file_get_contents, and then to the format input fscanf, finally chose the more mature and stable read Ini method.
The entire main program has only two files zipurl.php, index.php
The zipurl.php file is as follows:
Copy CodeThe code is as follows: <?php
This file is used to convert URLs
Organize URLs
function Dealurl ($url)
{
if ($url [4]!= ': ') $url = '/http '. $url;
return $url;
}
function Ranum ()
{
$str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$tmp = $str [Mt_rand (0,35)]. $str [Mt_rand (0,35)]. $str [Mt_rand (0,35)]. $str [Mt_rand (0,35)]. $str [Mt_rand (0,35)];
return $tmp;
}
Deposit Number
function Zipurl ($urls)
{
Check the number to heavy
$handle = fopen ("Url.tmp", "r+");
$array =parse_ini_file ("Url.tmp", true);
if (Array_search ($urls, $array)) return Array_search ($urls, $array);
$num =ranum ();
fprintf ($handle, "%s=%s\r", $num, $urls);
Fclose ($handle);
return $num;
}
function Main ()
{
if ($url =$_get[' url ')
{
$url =dealurl ($url);
$url =zipurl ($url);
echo "http://localhost/?". $url;
}
}
Main ();
?>
<title>ZIP your URL</title>
The index.php file is as follows:
Copy the Code code as follows: <?php
Check number
Short Access Section
function Readfiles ($strs)
{
$array =parse_ini_file ("Url.tmp", true);
Var_dump ($array);
return $array [$strs];
}
function Main ()
{
Go to Module
if ($str =$_server[' query_string ')
Echo ';
}
Main ();
Statistics section
?>
ZIP your URL
Temp file url.tmp:
Aaaaa=http://baidu.com
The effect is as follows:
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/960714.html www.bkjia.com true http://www.bkjia.com/PHPjc/960714.html techarticle PHP Short-Address conversion implementation method, PHP Conversion Example of this article describes the PHP short-address conversion implementation method. Share to everyone for your reference. The specific analysis is as follows: From yesterday afternoon to now overturned a ...