PHP sha1 Problems

Source: Internet
Author: User
{Code...} Do I want these 20 characters instead of binary? To be clear, this function outputs a binary value of BITs (that is, 20 bytes). Each 8 bits binary value corresponds to a character of the ASCII code, so this 160bit binary pair...

  

I want these 20 characters instead of binary. Is there any simple way?

To be clear, this function outputs a binary value of BITs (that is, 20 bytes). Each 8 bits binary value corresponds to a character of the ASCII code, therefore, the-bit binary value corresponds to 20 characters, and I want the 20 characters.

This problem has been disabled. Cause: it is the same as an existing problem.

Reply content:

  

I want these 20 characters instead of binary. Is there any simple way?

To be clear, this function outputs a binary value of BITs (that is, 20 bytes). Each 8 bits binary value corresponds to a character of the ASCII code, therefore, the-bit binary value corresponds to 20 characters, and I want the 20 characters.

If I do not understand it correctly, the "binary" returned by it is exactly what you want, and you may fall into the trap of your own ideas.

This is a simple program that outputs the ASCII values of 20 characters in turn. After a simple look, we know that many of them are in non-printable characters (with a value smaller than 32) and extended areas (with a value greater than 127 ), the location of the extended area is used for UTF-8 and GB encoding to indicate multi-byte encoding. Therefore, in these environments, a single byte in the Encoding Area is meaningless, that is, garbled characters may appear.

$x = sha1("Shanghai", true);for ($i = 0; $i < strlen($x); $i++) {    echo $x[$i] . "\t" . ord($x[$i]) . "\n";}

See ASCII table: http://www.ascii-code.com/

Ignore this answer downstairs

I don't know if this is the result you want:


  

Reference: http://php.net/manual/en/function.sha1.php

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.