This article mainly introduces the php short address conversion implementation method, which involves the URL and string operation skills and has some reference value. For more information, see
This article mainly introduces the php short address conversion implementation method, which involves the URL and string operation skills and has some reference value. For more information, see
This article describes how to implement php short address conversion. Share it with you for your reference. The specific analysis is as follows:
From yesterday afternoon to now I overturned one information storage solution after another, from mysql to file_get_contents with unlimited memory, and then to formatting the input fscanf ,, finally, we chose a mature and stable method for reading ini.
The main program only has two files: zipurl. php and index. php.
The zipurl. php file is as follows:
The Code is as follows:
<? Php
// This file is used to convert the url
// Sort URLs
Function dealurl ($ url)
{
If ($ url [4]! = ':') $ Url = 'HTTP: // '. $ url;
Return $ url;
}
Function ranum ()
{
$ Str = "0123456789 abcdefghijklmnopqrstuvwxyz ";
$ 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;
}
// Save the number
Function zipurl ($ urls)
{
// Check the number for deduplication
$ 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 ();
?>
ZIP your URL
The index. php file is as follows:
The Code is as follows:
<? Php
// Check the ID
// Short address access part
Function readfiles ($ strs)
{
$ Array = parse_ini_file ("url. tmp", true );
Var_dump ($ array );
Return $ array [$ strs];
}
Function main ()
{
// Switch to the module
If ($ str = $ _ SERVER ['query _ string'])
Echo'