在查阅php文档时,关于函数的介绍经常会看到注明是否“二进制安全”。那么二进制安全是什么含义呢?
以下是摘自知乎张砸锅的回答:
维基百科上搜索了一下:
Binary-safe is a computer programming term mainly used in connection with string manipulating functions. A binary-safe function is essentially one that treats its input as a raw stream of data without any specific format. It should thus work with all 256 possible values that a character can take (assuming 8-bit characters).
二进制安全是一种主要用于字符串操作函数相关的计算机编程术语。一个二进制安全功能(函数),其本质上将操作输入作为原始的、无任何特殊格式意义的数据流。其在操作上应包含一个字符所能有的256种可能的值(假设为8位字符)。
作者:张砸锅那么什么是特殊格式呢?
Special characters:Most functions are not binary safe when using any special or markup characters, such as escape codes or those that expect null-terminated strings. A possible exception would be a function whose explicit purpose is to search for a certain character in a binary string.
大多数的函数当其使用任何特别的安全或标记字符,如转义码,还是那些期望 null 结尾的字符串,不是二进制安全的。一个可能的例外将其明确的目的是要搜索的二进制字符串中的某些字符的函数。
数据格式化:
Data formatBinary safe functions are required when working with data of unknown format (otherwise the format would not be preserved) such as arbitrary files, encrypted data, and the like. The length of the data must be known by the function in order to operate on the entirety of the data.
在对未知格式的数据(尽管此格式无需保存),例如随意的文件、加密数据及类似情况时,二进制安全功能是必须的。数据长度须知以便函数操作整体数据。
链接:https://www.zhihu.com/question/28705562/answer/41815266
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。