Create a short address (var_export) in php-php Tutorial

Source: Internet
Author: User
Php creates a short address (var_export) and submits the shorten. php :?? & Lt; formmethodpostactionshow. php & gt; & lt; inputtypetextnameurlvalue & gt; & l create a short address (var_export) in php)

Submit page shorten. php:

?

?

? 

?

Processing 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 += pow($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 * $bcp);}$out = strrev($out); // reverse}return $out;}?>
?

?

Link page? Shorturls. php

?

?

 
?

?

?

Principle: store the submitted URL in the array and generate a unique key for it. then, store the URL in the text. of course, you can also store the URL in the database, this instance is stored in text.

?

Some functions:

?

1. array_search () function

?

Array_search (value, array, strict)

?

The array_search () function is the same as the in_array () function. you can find a key value in the array. If this value is found, the key name of the matching element is returned. If not found, false is returned.

?

2 .? Var_export ()? Function

?

?

This function returns the structure information about the variables passed to this function. it is similar to var_dump (). The difference is that the returned representation is legal PHP code.

You can set the second parameter of the function to TRUE to return the expression of the variable.

?

Compare var_export () and var_dump ().

?

?

?

What is the accept page? Redirect. php

?

?

 ?

This page must be used in combination with. htaccess or. waccess

?

?

RewriteEngine On RewriteRule ^s=(.*)$ /redirect.php?uid=$1 [R=301,L]
?

?

?

?

Association:

Php creates short ID Create short IDs with PHP-Like Youtube or TinyURL?

?

?

If you have any questions, please leave a message ~

?

?

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.