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

  • SEARCH
  • Home
  • 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 6830395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:36:45+00:00 2026-05-26T22:36:45+00:00

Given a randomly generated string, how do I convert it to make it URL

  • 0

Given a randomly generated string, how do I convert it to make it URL safe — and then “un convert” it?

PHP’s bin2hex function (see: http://www.php.net/manual/en/function.bin2hex.php) seems to safely convert strings into URL safe characters. The hex2bin function (see: http://www.php.net/manual/en/function.hex2bin.php) is probably not ready yet. The following custom hex2bin function works sometimes:

function hex2bin($hexadecimal_data)
{
    $binary_representation = '';

    for ($i = 0; $i < strlen($hexadecimal_data); $i += 2)
    {
        $binary_representation .= chr(hexdec($hexadecimal_data{$i} . $hexadecimal_data{($i + 1)}));
    }

    return $binary_representation;
}

It only works right if the input to the function is a valid bin2hex string. If I send it something that was not a result of bin2hex, it dies. I can’t seem to get it to throw an exception in case something is wrong.

Any suggestions what I can do? I’m not set on using hex2bin/bin2hex. All I need to to be able to convert a random string into a URL safe string, then reverse the process.

  • 1 1 Answer
  • 1 View
  • 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-26T22:36:46+00:00Added an answer on May 26, 2026 at 10:36 pm

    What you want to do is URL encode/decode the string:

    $randomString = ...;
    
    $urlSafe = urlencode($randomString);
    
    $urlNotSafe = urldecode($urlSafe); // == $randomString
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the string is randomly generated, some are shorts and some are long. short
given a script that generates a string of 12 characters randomly generated, how many
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
I have a string that is randomly generated: polymer_str = diol diNCO diamine diNCO
Given a series of randomly generated data how can I figure out how random
I have a 2D image randomly and sparsely scattered with pixels. given a point
I'd like to create a function which will generate a 3 char key string
Generating a truly random string of a given length is a fairly straightforward (and
Given a randomly distributed set of keys, with each key mapped to a set
Looking for feedback. I am building a django app where users are given randomly

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.