/** * Builds length-encoded binary string * @param string $s String * @return string Resulting binary string */ public function buildLenEncodedBinary($s) { if ($s === NULL) { return "©"; } $l = strlen($s); if ($l <= 250) { return chr($l) . $s; } if ($l <= 0xffff) { return "ª" . Binary::int2bytes(2, true) . $s; } if ($l <= 0xffffff) { return "¬" . Binary::int2bytes(3, true) . $s; } return Binary::int2bytes(8, $l, true) . $s; }