Home >Backend Development >PHP Tutorial >PHP short address conversion implementation method, PHP conversion_PHP tutorial

PHP short address conversion implementation method, PHP conversion_PHP tutorial

WBOY
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();
?>

ZIP your URL





           




The index.php file is as follows:

Copy code The code is as follows:
//查号  
//短址访问部分 
function readfiles($strs) 

    $array=parse_ini_file("url.tmp",true); 
    var_dump($array); 
    return $array[$strs]; 

function main() 

    //转到模块 
    if($str=$_SERVER['QUERY_STRING']) 
    echo ''; 

main(); 
//统计部分 
?> 
 
ZIP your URL 
 
 
 
 
   
 
     
 
         
     
 
       
   
 
 
 

临时文件url.tmp:
aaaaa=http://baidu.com

运行效果如下图所示:

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/960714.htmlTechArticlephp短址转换实现方法,php转换 本文实例讲述了php短址转换实现方法。分享给大家供大家参考。具体分析如下: 从昨天下午到现在 推翻了一...
Statement:
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