Explanation One:
In PHP, there is the concept of string.
In string, the size of each character is byte (compared to PHP, each character in Java is character, which is the UTF8 character, and each character in the C language can be selected at compile time).
In byte, there are ASCII code characters, such as ABC,123,ABC, and some special characters, such as carriage return, backspace, and so on.
Many of the special characters are not displayed. Or, they do not display the standard, for example, code 65 to where the letter A, code 97 to where the character a, backspace in some places to display a symbol, in some places will really return the previous character.
PHP is based on C, so many of the descriptions are in the C comparison. In the C string, a classic definition is to encode 0 as the end of a string. So, suppose such a string, where the 3-character encoding is 97,0,97. So, if there is str_replace equivalent function in C, use it to change 97 to 98, then this function reads to 0, it is considered to be finished, it will get 98,0,97. corresponding to it, PHP str_replace is binary security, then the 0 will not be considered a special end symbol, so the result is 98,0,98.
"Binary security" in the PHP document, basically is the meaning of: C language functions similar to the function will be special processing of some characters, and PHP this function for all characters equal, do not worry about special characters affect processing, especially do not worry about encoding 0 characters.
explanation Two: the strlen function in C is not binary safe, because it relies on the special character ' \ s ' to determine whether the string ends, so for the string str = "1234\0123", strlen (str) =4 and in PHP , the strlen function is binary safe because it does not have a special explanation for any character (including ' m '), so in PHP, strlen (str) =8 So, I understand the binary security means: Only care about the binary string, do not care about the specific format, Only strict binary data access is required. No attempt is made to parse the data in a particular format.
Explanation of PHP binary security