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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:12:30+00:00 2026-05-15T13:12:30+00:00

I’m trying to upgrade from PHP 5.2.x to 5.3.2 on my server. Problem is,

  • 0

I’m trying to upgrade from PHP 5.2.x to 5.3.2 on my server. Problem is, I relying on the broken implementation of PHP’s ezmlm_hash() (the bug is outlined here: http://bugs.php.net/bug.php?id=47969).

My first thought was to rewrite the broken version of the native PHP function (which is written in C) myself in PHP and use that in my code, instead of modifying the PHP source code and having to compile PHP from source.

Here is the C version of the code:

PHP_FUNCTION(ezmlm_hash)
{
    char *str = NULL;
    unsigned int h = 5381L;
    int j, str_len;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
                              &str, &str_len) == FAILURE) {
        return;
    }

    for (j = 0; j < str_len; j++) {
        h = (h + (h << 5)) ^ (unsigned long) (unsigned char) tolower(str[j]);
    }

    h = (h % 53);

    RETURN_LONG((int) h);
}

here is what I’ve written in PHP:

function ezmlm_hash_mine($email_address){
    $h = 5381;
    $email_length = strlen($email_address);
    for($x=0;$x<$email_length;$x++){
        $chr = strtolower($email_address[$x]);
        $h = ($h + ($h << 5)) ^ ( ord($chr) );
    }

    $h = $h % 53;
    return $h;
}

I’m using a 64-bit machine. The two functions output different results:

$email_addresses = array(
    'test@example.com',
    'mike@example.com',
);

print('<PRE>');

foreach($email_addresses as $email_address){
    print(ezmlm_hash($email_address).PHP_EOL);
    print(ezmlm_hash_mine($email_address).PHP_EOL.PHP_EOL);
}

output:

23
-52

15
-21

I know I probably have some precision or typing issues, I’m just not sure how to fix it. Any help would be greatly appreciated!

UPDATE

When I run thes the code on 32 bit machines, they both output the new corrected values:

12
12

45
45

I think this has something to do with the modulo operator… does anyone know the PHP equivalent of the C modulo operator? % in PHP behaves differently!

UPDATE 2

It appears as if this is not possible with vanilla PHP, as it’s floating point arithmetic doesn’t have enough precision, and weirdness in . I’ll have to install either BCMath or GMP. Thanks for everyone’s insight.

  • 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-15T13:12:31+00:00Added an answer on May 15, 2026 at 1:12 pm

    try this EDIT truncate to 32 bits after calculation:

    function ezmlm_hash_mine($email_address){
        $h = gmp_init(5381);
        $d = gmp_setbit(0, 64);
        $d32 = gmp_setbit(0, 32);
        $email_length = strlen($email_address);
    
        $chr = strtolower($email_address);
    
        for($x=0;$x<$email_length;$x++){    
            $h = gmp_mod(gmp_xor(gmp_mod(gmp_add($h, gmp_mod(gmp_mul($h, "32"), $d)), $d), ord($chr[$x])), $d32);
        }
    
        $h = gmp_mod($h, 53);
        return gmp_intval($h);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.