PHP Create short address (var_export)
Submit Page shorten.php:
?
?
?
?
Handling page show.php:
?
?
'); fclose ($file); $output = ' Original Url: '. $url. '
Shorten ulr:http://www.yourdomain.com/api/s= '. $uif. ';} else $output = ' access error ';} else{$uif = Array_search ($url, $shortUrls); $output = ' Original URL: '. $url. '
Shorten ulr:http://www.yourdomain.com/api/s= '. $uif. ';} echo $output. '
Back ';}? >
?
?
Link page? functions.php
?
?
0) $out-= POW ($base, $pad _up);} $out = sprintf ('%F ', $out); $out = substr ($out, 0, Strpos ($out, '. '));} else {//Digital number-->> alphabet Letter Codeif (is_numeric ($pad _up)) {$pad _up--;if ($pad _up > 0) $in + = PO W ($base, $pad _up);} $out = ""; for ($t = Floor (log ($in, $base)); $t >= 0; $t-) {$bcp = Bcpow ($base, $t), $a = floor ($in/$bcp)% $base; $out = $out. substr ($index, $a, 1); $in = $in-($a * $BC p);} $out = Strrev ($out); Reverse}return $out;}? >?
?
Link page? shorturls.php
?
?
?
?
?
Principle: The submitted URL is stored in the array, and a unique key is generated, then the array is stored in the text, of course, you can also be stored in the database, this instance is stored in the text.
?
Explanation of some functions:
?
1. Array_search () function
?
Array_search (value,array,strict)
?
The Array_search () function, like In_array (), looks for a key value in the array. If the value is found, the key name of the matching element is returned. Returns False if it is not found.
?
2.?var_export ()? function
?
?
This function returns the structure information about the variable passed to the function, similar to Var_dump (), unlike the PHP code whose returned representation is valid.
You can return the representation of a variable by setting the second argument of the function to TRUE.
?
Compare Var_export () and Var_dump ().
?
?
?
Finally, accept the page? redirect.php
?
?
!--? phpinclude ' shorturls.php '; $uid = $_get[' uid ']; $addr = ($uid and array_key_exists ($ UID, $shortUrls))? $shortUrls [$uid]: '/'; header (' Location: ' $addr); ? This page needs to be combined with. htaccess or. waccess
?
?
rewriteengine on Rewriterule ^s= (. *) $/redirect.php?uid=$1 [r=301,l]
? ?
?
?
Association:
php Create a short ID for creating a shorter IDs with Php-like Youtube or tinyurl?
?
?
If the problem, please leave a message ~
?
?