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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:47:26+00:00 2026-05-23T13:47:26+00:00

I want to get the first eight bytes of a calculated MD5 string. In

  • 0

I want to get the first eight bytes of a calculated MD5 string. In Ruby I do this:

Digest::MD5.digest("foo")[0, 8]

What is the best way to do this in PHP?

EDIT: I don’t want it as a String, which substr() returns. I thought of calling md5("foo", true), where the true parameter enables returning binary. I want to cut the 16 bytes to 8 bytes.

  • 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-23T13:47:27+00:00Added an answer on May 23, 2026 at 1:47 pm

    If I remember correctly, using md5() and hex2bin() should do what you want:

    substr(hex2bin(md5("foo")), 0, 8);
    

    EDIT:

    If the hex2bin() function is not defined, you can alternatively implement it yourself using this function (from here):

    function hex2bin($hexdata) { 
      $bindata=""; 
    
      for ($i=0;$i<strlen($hexdata);$i+=2) { 
        $bindata.=chr(hexdec(substr($hexdata,$i,2))); 
      } 
    
      return $bindata; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python, if I want to get the first n characters of a string
This is very basic magento question i guess. I want to first get all
So I want to get the first <a> tag in this <div> . This
I have a date string in format 08/1999 I want to get the first
I want to get the first letter of a string and I've noticed that
I want to get the first 8 bytes or so of a file without
I want to get the first string that matches my regular expression. For example
I have this equation: f(a,b,x)=t0-a+(a^2*(1+((x-x0)^2/b^2)))^0.5 if I want get the first derivative: df(a,b,x)/d(a,b) for
I want to get the first place where 2 string vary from each other.
I use the following structure Dictionary<string, List<object>> I want to get the first element

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.