PHP 字符串 md5()函數
PHP字符串md5()是預定義函數。愛掏網 - it200.com它用于計算字符串的MD5哈希值。愛掏網 - it200.com它使用了RSA DATA安全性。愛掏網 - it200.com它將哈希值以32個字符的十六進制數返回。愛掏網 - it200.com
注意:由于這個哈希算法的快速特性,我們不應該將此函數用于安全密碼。愛掏網 - it200.com
md5(string,raw);
參數 | 描述 | 必需/可選 |
---|---|---|
String | 指定要計算的字符串。愛掏網 - it200.com | 必需 |
raw | 指定十六進制或二進制格式 | 可選 |
- TRUE – 原始 16 個字符的二進制格式
- FALSE – 默認。愛掏網 - it200.com32 個字符的十六進制數
示例1
<?php
str = "PHP";
echo "Your string is:".str;
echo "<br>";
echo "By using md5() functon:".md5($str);
?>
輸出:
Your string is:PHP
By using md5() functon:2fec392304a5c23ac138da22847f9b7c
示例2
<?php
str = 'PHP';
if (md5(str) =='2fec392304a5c23ac138da22847f9b7c'){
echo "'PHP' string is equall to encrypted string";
}
?>
輸出:
'PHP' string is equall to encrypted string
示例3
<?php
str = "PHP";
echo "Your string is: ".str."<br>";
echo "TRUE - Raw 16 character binary format: ".md5(str, TRUE)."<br>";
echo "FALSE - 32 character hex number: ".md5(str)."<br>";
?>
輸出:
Your string is: PHP
TRUE - Raw 16 character binary format: /ì9# ¥?:á8ú"??|
FALSE - 32 character hex number: 2fec392304a5c23ac138da22847f9b7c
示例4
<?php
str = "PHP";
echo "Your string is:".str."<br>";
echo "By using md5()fnction:".md5(str);
if (md5(str) == "8b1a9953c4611296a827abf8c47804d7")
{
echo "<br>Hello PHP!";
exit;
}
?>
輸出:
Your string is: PHP
By using md5() function: 2fec392304a5c23ac138da22847f9b7c
注意:加密值 “8b1a9953c4611296a827abf8c47804d7” 并不等于 “PHP” 字符串,因此無法顯示”Hello PHP”消息。愛掏網 - it200.com
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。