How to Convert Text to Crc32, md5 and Sha1 in PHP

In this tutorial, we are going to learn how to Convert Text to Crc32, md5, and Sha1 in PHP. You will know which is the roughest among the three in terms of the length they generate individually. CRC32 creates a 32-bit hash, md5 creates a 128-bit hash, and Sha1 creates 160-bit (20-byte) hash value. You can use these three to encrypt password from the registering system. Related code: Convert Text in Sha1 Related code: Convert Text in CRC32 Related code: Convert Text in md5 Creating simple TextBox, buttons, and another TextBox for viewing the result of CRC32, Sha1, and md5 to the form field as in the image below. Result Here's the source code of the image above.
  1. <div style="border:2px solid blue; background:azure; width:500px; padding:20px;">
  2. <form method="post">
  3. <h2 style="color:blue; font-family:cursive;">Convert Text to Crc32, Sha1, and md5</h2><br>
  4. <input type="text" name="convert" style="padding:5px; font-size:18px; width:245px; font-family:cursive;" placeholder="Type Anything . . . . ." autofocus="autofocus">
  5. <input type="submit" name="convertion" value="Convert" style="padding:5px; font-family:cursive; font-size:18px; color:blue; background:azure; border:1px solid blue; border-radius:4px; cursor:pointer;">
  6. </form>
  7. <br>
  8. <h2 style="color:blue; font-family:cursive;">Crc32 Result</h2><br>
  9. <input type="text" value="" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
  10.  
  11. <h2 style="color:blue; font-family:cursive;">Sha1 Result</h2><br>
  12. <input type="text" value="" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
  13.  
  14. <h2 style="color:blue; font-family:cursive;">MD5 Result</h2><br>
  15. <input type="text" value="" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
  16. </div>
For the conversion of text to CRC32, Sha1, and md5 we are going to put this PHP query to the TextBox to view the result. This is the PHP query.
  1. <?php
  2. if(isset($_POST['convertion'])){ echo crc32($_POST['convert']); }
  3. ?>
  4.  
  5. <?php
  6. if(isset($_POST['convertion'])){ echo sha1($_POST['convert']); }
  7. ?>
  8.  
  9. <?php
  10. if(isset($_POST['convertion'])){ echo md5($_POST['convert']); }
  11. ?>
Now, let's put to the TextBox.
  1. <h2 style="color:blue; font-family:cursive;">Crc32 Result</h2><br>
  2. <input type="text" value="<?php if(isset($_POST['convertion'])){ echo crc32($_POST['convert']); } ?>" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
  3.  
  4. <h2 style="color:blue; font-family:cursive;">Sha1 Result</h2><br>
  5. <input type="text" value="<?php if(isset($_POST['convertion'])){ echo sha1($_POST['convert']); } ?>" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
  6.  
  7. <h2 style="color:blue; font-family:cursive;">MD5 Result</h2><br>
  8. <input type="text" value="<?php if(isset($_POST['convertion'])){ echo md5($_POST['convert']); } ?>" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
Here's the result. Result The complete source code.
  1. <!DOCTYPE html>
  2. <title>Convert Text to Crc32, md5 and Sha1</title>
  3. </head>
  4.  
  5. <div style="border:2px solid blue; background:azure; width:500px; padding:20px;">
  6. <form method="post">
  7. <h2 style="color:blue; font-family:cursive;">Convert Text to Crc32, Sha1, and md5</h2><br>
  8. <input type="text" name="convert" style="padding:5px; font-size:18px; width:245px; font-family:cursive;" placeholder="Type Anything . . . . ." autofocus="autofocus">
  9. <input type="submit" name="convertion" value="Convert" style="padding:5px; font-family:cursive; font-size:18px; color:blue; background:azure; border:1px solid blue; border-radius:4px; cursor:pointer;">
  10. </form>
  11. <br>
  12. <h2 style="color:blue; font-family:cursive;">Crc32 Result</h2><br>
  13. <input type="text" value="<?php if(isset($_POST['convertion'])){ echo crc32($_POST['convert']); } ?>" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
  14.  
  15. <h2 style="color:blue; font-family:cursive;">Sha1 Result</h2><br>
  16. <input type="text" value="<?php if(isset($_POST['convertion'])){ echo sha1($_POST['convert']); } ?>" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
  17.  
  18. <h2 style="color:blue; font-family:cursive;">MD5 Result</h2><br>
  19. <input type="text" value="<?php if(isset($_POST['convertion'])){ echo md5($_POST['convert']); } ?>" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
  20. </div>
  21.  
  22. </body>
  23. </html>
Related code: Convert Text in Sha1 Related code: Convert Text in CRC32 Related code: Convert Text in md5 Hope that this tutorial will help you a lot. Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment