Binary safe

A binary safe function means the function will work correctly when you pass it arbitrary binary data. i.e.
  1. Strings containing non-ASCII bytes. (i.e. bangla font)
  2.  Null bytes. (i.e. null-terminated)

For instance, if PHP's strlen function worked like C standard library strlen, the result here would be wrong:
$str = "abc\x00abc";
echo strlen($str); //gives 7, not 3!
More examples:
<?php

    $string1 = "Hello";
    $string2 = "Hello\x00World";

    // This function is NOT ! binary safe
    echo strcoll($string1, $string2); // gives 0, strings are equal.

    // This function is binary safe
    echo strcmp($string1, $string2); // gives <0, $string1 is less than $string2.

?>
\x indicates hexadecimal notation. See: PHP strings
0x00 = NULL
0x04 = EOT (End of transmission)
ASCII table to see ASCII char list.

Labels: ,

© copyright-2020 Rejaul