• Avail guidance to develop Drupal modules & Drupal themes
  • Share and get review of your code
  • Get Access to free CodeBooks and ThemeBooks
  • Drupal 5, 6 and 7 covered

Userpoints Meter

0 Points /1000 Points

URL Shortner

in

This CodeLet generates and returns a short url when providing a long url. This is useful especially when you have a really long url and you want paste in forums, discussion boards, emails etc. You can even bookmark this short url. Here, only url shortning algorithm added. You can build other features around it. This is a very primary algorithm and you can improve it further.

<?php
 
/**
* @author Drupal Developer <http://twitter.com/DrupalD>
*/
function _get_short_url() {
 
$sn__rand = mt_rand(100000000000, 999999999999);
 
$am__id = str_split($sn__rand, 3);
  for (
$i = 0; $i < count($am__id); $i++) {
    if (
is_numeric($am__id[$i]) && $am__id > 0) {
      if (
$am__id[$i] < 65) {
        if (
$am__id[$i] >= 48 && $am__id[$i] <= 57) {
         
$am__id[$i] = chr($am__id[$i]);
        }
      }
      else if (
$am__id[$i] >= 65 && $am__id[$i] <= 90 && $am__id[$i] >= 97 && $am__id[$i] <= 122) {
       
$am__id[$i] = chr($am__id[$i]); 
      }
      else if (
$am__id[$i] > 122) {
       
$am__id[$i] = chr(65 - $am__id[$i]); 
      }
     
$am__char[] = $am__id[$i];
    }
  }
  return
implode("", $am__char);

?>

0
Your rating: None
Syndicate content

Recent comments