PHP Short-Address conversion implementation method, PHP conversion _php Tutorial

Source: Internet
Author: User
Tags file url php programming

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 ...

  • 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.