十一、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() 将避免把单词断开。