位置: 编程技术 - 正文

PHP字符串函数crc32()的用法(php字符串定义)

编辑:rootadmin
crc

推荐整理分享PHP字符串函数crc32()的用法(php字符串定义),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:php操作字符串,php处理字符串函数,php操作字符串,php字符串定义,php 字符串包含,php 字符串函数,php 字符串处理,php中字符串函数,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4 >= 4.0.1, PHP 5)

crc — 计算一个字符串的 crc 多项式

说明 int crc ( string $str )

生成 str 的 位循环冗余校验码多项式。这通常用于检查传输的数据是否完整。

Warning

由于 PHP 的整数是带符号的,所以在 位系统上许多 crc 校验码将返回负整数。 尽管在 位上所有 crc() 的结果将都是正整数。

因此你需要使用 sprintf() 或 printf() 的“%u”格式符来获取表示无符号 crc 校验码的字符串。

For a hexadecimal representation of the checksum you can either use the "%x" formatter of sprintf() or printf() or the dechex() conversion functions, both of these also take care of converting the crc() result to an unsigned integer.

Having bit installations also return negative integers for higher result values was considered but would break the hexadecimal conversion as negatives would get an extra 0xFFFFFFFF######## offset then. As hexadecimal representation seems to be the most common use case we decided to not break this even if it breaks direct decimal comparisons in about % of the cases when moving from to bits.

PHP字符串函数crc32()的用法(php字符串定义)

In retrospect having the function return an integer maybe wasn&#;t the best idea and returning a hex string representation right away (as e.g. md5() does) might have been a better plan to begin with.

For a more portable solution you may also consider the generic hash(). hash("crcb", $str) will return the same string as dechex(crc($str)).

参数

str

要校验的数据。

返回值

返回 str crc 校验的整数。

范例

Example #1 显示一个 crc 校验码

示例中的第二行演示了如何使用 printf() 函数转换校验码:

<?php$checksum=crc("Thequickbrownfoxjumpedoverthelazydog.");printf("%un",$checksum);?>

参见

hash() - Generate a hash value (message digest) md5() - 计算字符串的 MD5 散列值 sha1() - 计算字符串的 sha1 散列值

PHP字符串函数fprintf()的用法 fprintf(PHP5)fprintf将格式化后的字符串写入到流说明intfprintf(resource$handle,string$format[,mixed$args[,mixed$...]])写入一个根据format格式化后的字符串到由handle句柄打

PHP字符串函数crypt()的用法 crypt(PHP4,PHP5)crypt单向字符串散列说明stringcrypt(string$str[,string$salt])crypt()返回一个基于标准UNIXDES算法或系统上其他可用的替代算法的散列字符串。有些系

PHP字符串函数echo()的用法 echo(PHP4,PHP5)echo输出一个或多个字符串说明voidecho(string$arg1[,string$...])输出所有参数。echo不是一个函数(它是一个语言结构),因此你不一定要使用小括

本文链接地址:https://www.jiuchutong.com/biancheng/279863.html 转载请保留说明!

上一篇:PHP字符串函数explode()的用法(php字符串数组函数)

下一篇:PHP字符串函数fprintf()的用法(php字符串赋值)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络