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 8834653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:04:27+00:00 2026-06-14T09:04:27+00:00

My website use various resources from a single domain, for example: http://static.example.com/javascript/common.js http://static.example.com/javascript/common.css http://static.example.com/javascript/menu/menu.js

  • 0

My website use various resources from a single domain, for example:

http://static.example.com/javascript/common.js
http://static.example.com/javascript/common.css
http://static.example.com/javascript/menu/menu.js
http://static.example.com/javascript/menu/menu.css
http://static.example.com/images/1804/logo/02000100.jpg
http://static.example.com/images/1804/headers/main/09400060.png
http://static.example.com/images/1804/headers/home/1101/06900200-01.jpg
http://static.example.com/images/1804/headers/home/1101/06900200-02.jpg

I need a very simple string hashing function that maps these URLs to numbers, the numbers being 0, 1, 2 and 3. The algorithm should be deterministic and uniform. I have tagged the question PHP but a generic answer is acceptable.

You might have guessed why I need this; I plan to change the URLs to, for example:

http://0.static.example.com/javascript/common.js
http://2.static.example.com/javascript/common.css
  • 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-06-14T09:04:29+00:00Added an answer on June 14, 2026 at 9:04 am

    I prefer doing a crc32 hash of the string, and taking its modulo with the limit.

    Code:

    function numeric_hash($str, $range) {
        return sprintf("%u", crc32($str)) % $range;
    }
    

    Usage:

    $str = "http://static.example.com/javascript/common.js
    http://static.example.com/javascript/common.css
    http://static.example.com/javascript/menu/menu.js
    http://static.example.com/javascript/menu/menu.css
    http://static.example.com/images/1804/logo/02000100.jpg
    http://static.example.com/images/1804/headers/main/09400060.png
    http://static.example.com/images/1804/headers/home/1101/06900200-01.jpg
    http://static.example.com/images/1804/headers/home/1101/06900200-02.jpg";
    $urls = explode("\n", $str);
    
    foreach($urls as $url) {
        echo numeric_hash($url, 4) . "\n";
    }
    

    Output:

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

Sidebar

Related Questions

I've found various methods: Check serverlist offline / online PHP http://css-tricks.com/snippets/php/check-if-website-is-available/ But was curious
I am a hobbyist webdesigner, use html and CSS for testing various website designs.
Background: I've created a website that displays currency rates from various countries. I use
I'm trying to use gettext add localisation support to my website. I've followed various
When writing programs (C#.NET) I'll commonly use external libraries I've downloaded from various websites
My website doesn't use Flash or any plugins; just javascript (jQuery, Google Maps). It
I have a website, in this website I use various 3rd party PHP scripts,
Part of our core product is a website CMS which makes use of various
I use External JavaScripts in a website as I always try to keep JavaScript
I have a dynamic website, and use the share button on various pages of

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.