Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6557389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:04:04+00:00 2026-05-25T13:04:04+00:00

what I’m wanting is to convert an integer into a string. For example, 123456789

  • 0

what I’m wanting is to convert an integer into a string. For example, 123456789 may become 8GFsah93r … you know like Youtube, Pastebin and what not. I then want to convert it back.

I’m working with large integers, for example: 131569877435989900

Take a look at this link: http://codepad.viper-7.com/wHKOMi

This is my attempt using a function I found on the web, obviously… it’s not correctly converting back to integer. I’m needing something that does this realiably.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:04:05+00:00Added an answer on May 25, 2026 at 1:04 pm

    Ok, one of the ideas is to use a character array as a representation of a numeric system. Then you can convert from base 10 to base x and vica-versa. The value will be shorter and less readable (altought, you should encrypt it with a two-way crypter if it must be secure).

    A solution:

    final class UrlShortener {
    
        private static $charfeed = Array(
        'a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m',
        'M','n','N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y',
        'z','Z','0','1','2','3','4','5','6','7','8','9');
    
        public static function intToShort($number) {
            $need = count(self::$charfeed);
            $s = '';
    
            do {
                $s .= self::$charfeed[$number%$need];
                $number = floor($number/$need);
            } while($number > 0);
    
            return $s;
        }
    
        public static function shortToInt($string) {
            $num = 0;
            $need = count(self::$charfeed);
            $length = strlen($string);
    
            for($x = 0; $x < $length; $x++) {
                $key = array_search($string[$x], self::$charfeed);
                $value = $key * pow($need, $x);
                $num += $value;
            }
    
            return $num;
        }
    }
    

    Then you can use:

    UrlShortener::intToShort(2);
    UrlShortener::shortToInt("b"); 
    

    EDIT

    with large numbers, it does not work. You should use this version (with bcmath http://www.php.net/manual/en/book.bc.php ) with very large numbers:

    final class UrlShortener {
    
        private static $charfeed = Array(
        'a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m',
        'M','n','N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y',
        'z','Z','0','1','2','3','4','5','6','7','8','9');
    
        public static function intToShort($number) {
            $need = count(self::$charfeed);
            $s = '';
    
            do {
                $s .= self::$charfeed[bcmod($number, $need)];
                $number = floor($number/$need);
            } while($number > 0);
    
            return $s;
        }
    
        public static function shortToInt($string) {
            $num = 0;
            $need = count(self::$charfeed);
            $length = strlen($string);
    
            for($x = 0; $x < $length; $x++) {
                $key = array_search($string[$x], self::$charfeed);
                $value = $key * bcpow($need, $x);
                $num += $value;
            }
    
            return $num;
        }
    }
    $original = 131569877435989900;
    $short = UrlShortener::intToShort($original);
    echo $short;
    echo '<br/>';
    $result = UrlShortener::shortToInt($short);
    echo $result;
    echo '<br/>';
    echo bccomp($original, $result);
    

    If something missing from here, please let me know, because it’s only a snippet from my library (I don’t wanna insert the whole thing here)

    negra

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I would like to count the length of a string with PHP. The string
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.