PHP short address conversion implementation method, PHP conversion_PHP tutorial
WBOYOriginal
2016-07-13 10:06:09795browse
How to implement php short address conversion, php conversion
The example in this article describes the implementation method of PHP short address conversion. Share it with everyone for your reference. The specific analysis is as follows:
From yesterday afternoon to now, I have overturned one information storage solution after another, from mysql to file_get_contents with unlimited memory, to fscanf for formatted input, and finally chose a more mature and stable method of reading ini. .
The entire main program has only two files zipurl.php and index.php
zipurl.php file is as follows:
Copy code The code is as follows:
//This file is used to convert url
//Organize url
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;
}
//Save account
function zipurl($urls)
{
//Directory check and duplicate removal
$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=%sr",$num,$urls);
fclose($handle);
Return $num;
}
function main()
{
If($url=$_GET['url'])
{
$url=dealurl($url);
$url=zipurl($url);
echo "http://localhost/?".$url;
}
}
main();
?>
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