十一、crc32() 函數計算一個字符串的 crc32 多項式。生成 string 參數的 32 位循環冗餘校驗碼多項式。該函數可用於驗證數據的完整性。php
注意:因爲 PHP 的整數是帶符號的,許多 crc32 校驗碼將返回負整數,所以您須要使用 sprintf() 或 printf() 的 "%u" 格式符來獲取表示無符號 crc32 校驗碼的字符串。web
在本例中,咱們將在使用以及不使用 "%u" 格式符的狀況下,輸出 crc32() 的結果(注意結果是相同的):算法
<?php $str = crc32("Hello world!"); echo 'Without %u: '.$str."<br />"; echo 'With %u: '; printf("%u",$str); ?>
輸出:數據庫
Without %u: 461707669 With %u: 461707669
在本例中,咱們將在使用以及不使用 "%u" 格式符的狀況下,輸出 crc32() 的結果(注意結果是不相同的):數組
<?php $str = crc32("Hello world."); echo 'Without %u: '.$str."<br />"; echo 'With %u: '; printf("%u",$str); ?>
輸出:安全
Without %u: -1959132156 With %u: 2335835140
十二、crypt() 函數返回使用 DES、Blowfish 或 MD5 加密的字符串。在不一樣的操做系統上,本函數的行爲不一樣,某些操做系統支持一種以上的算法類型。在安裝時,PHP 會檢查什麼算法可用以及使用什麼算法。函數
salt參數可選。用於增長被編碼字符數目的字符串,以使編碼更加安全。若是未提供 salt 參數,則每次調用該函數時會隨機生成一個。測試
確切的算法依賴於 salt 參數的格式和長度。編碼
下面是與 crypt() 函數一塊兒使用的一些常量。在安裝時,由 PHP 設置這些常量:加密
注意:解密算法是沒有的,這是一種單向加密方法
在本例中,咱們將測試不一樣的算法:
<?php if (CRYPT_STD_DES == 1) { echo "Standard DES: ".crypt("hello world")."\n<br />"; } else { echo "Standard DES not supported.\n<br />"; } if (CRYPT_EXT_DES == 1) { echo "Extended DES: ".crypt("hello world")."\n<br />"; } else { echo "Extended DES not supported.\n<br />"; } if (CRYPT_MD5 == 1) { echo "MD5: ".crypt("hello world")."\n<br />"; } else { echo "MD5 not supported.\n<br />"; } if (CRYPT_BLOWFISH == 1) { echo "Blowfish: ".crypt("hello world"); } else { echo "Blowfish DES not supported."; } ?>
輸出相似(依賴於操做系統):
Standard DES: $1$r35.Y52.$iyiFuvM.zFGsscpU0aZ4e. Extended DES not supported. MD5: $1$BN1.0I2.$8oBI/4mufxK6Tq89M12mk/ Blowfish DES not supported.
1三、explode() 函數把字符串分割爲數組。
語法:explode(separator,string,limit)
說明:本函數返回由字符串組成的數組,其中的每一個元素都是由 separator 做爲邊界點分割出來的子字符串。
separator 參數不能是空字符串。若是 separator 爲空字符串(""),explode() 將返回 FALSE。
若是 separator 所包含的值在string 中找不到,那麼 explode() 將返回包含 string 中單個元素的數組。若是設置了 limit 參數,
則返回的數組包含最多 limit 個元素,而最後那個元素將包含 string 的剩餘部分。若是 limit 參數是負數,則返回除了最後的 -limit 個元素外的全部元素。
此特性是 PHP 5.1.0 中新增的。
注意:參數 limit 是在 PHP 4.0.1 中加入的。因爲歷史緣由,雖然 implode() 能夠接收兩種參數順序,可是 explode() 不行。
你必須保證 separator 參數在 string 參數以前才行。
<?php $str = "Hello world. It's a beautiful day."; print_r (explode(" ",$str)); ?>
輸出:
Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )
1四、fprintf() 函數把格式化的字符串寫到指定的輸出流(例如:文件或數據庫)。
該函數返回被寫字符串的長度。
fprintf(stream,format,arg1,arg2,arg++)
stream——可選。規定在哪裏寫/輸出字符串。
format——必需。轉換格式。
arg1——必需。規定插到 format 字符串中第一個 % 符號處的參數。
arg2——可選。規定插到 format 字符串中第二個 % 符號處的參數。
arg++——可選。規定插到 format 字符串中第3、四等等 % 符號處的參數。
arg1, arg2, ++ 等參數將插入到主字符串中的百分號 (%) 符號處。該函數是逐步執行的。在第一個 % 符號中,插入 arg1,在第二個 % 符號處,插入 arg2,依此類推。
註釋:若是 % 符號多於 arg 參數,則您必須使用佔位符。佔位符被插入 % 符號以後,由數字和 "\$" 組成。請參見例子 3。
提示: 相關函數: printf()、 sprintf()、 vfprintf()、 vprintf() 以及 vsprintf()。
<?php $str = "Hello"; $number = 123; $file = fopen("test.txt","w"); echo ; ?>fprintf($file,"%s world. Day number %u",$str,$number)
輸出:
27
如下文本將寫入 "test.txt":
Hello world. Day number 123
<?php $number = 123; $file = fopen("test.txt","w"); ?>fprintf($file,"%f",$number);
輸出:
123.000000
使用佔位符:
<?php $number = 123; $file = fopen("test.txt","w"); ; ?>fprintf($file,"With 2 decimals: %1\$.2f\nWith no decimals: %1\$u",$number)
如下文本將寫入 "test.txt":
With 2 decimals: 123.00 With no decimals: 123
1五、hebrev() 函數把希伯來文本從右至左的流轉換爲左至右的流。只有 224 至 251 之間的 ASCII 字符,以及標點符號受到影響。
maxcharline——規定每行的最大字符數。若是可能,hebrev() 將避免把單詞斷開。