PHPDaemon\Core\Debug::exportBytes PHP Méthode

exportBytes() public static méthode

Export binary data
public static exportBytes ( string $str, boolean $all = false ) : string
$str string String
$all boolean Whether to replace all of chars with escaped sequences
Résultat string Escaped string
    public static function exportBytes($str, $all = false)
    {
        return preg_replace_callback('~' . ($all ? '.' : '[^A-Za-z\\d\\.\\{\\}$<>:;\\-_/\\\\=+]') . '~s', function ($m) use($all) {
            if (!$all) {
                if ($m[0] === "\r") {
                    return "\n" . '\\r';
                }
                if ($m[0] === "\n") {
                    return '\\n';
                }
            }
            return sprintf('\\x%02x', ord($m[0]));
        }, $str);
    }

Usage Example

Exemple #1
0
 public function perform()
 {
     $str = Request::getString($_REQUEST['str']);
     $size = Request::getInteger($_REQUEST['size']);
     $rounds = Request::getInteger($_REQUEST['rounds']);
     if (!$rounds) {
         $rounds = 24;
     }
     $salt = '$512=24';
     $hash = Crypt::hash($str, $salt);
     $hex = trim(str_replace('\\x', ' ', Debug::exportBytes(base64_decode($hash), true)));
     $this->req->setResult(['stringWithSalt' => $str . $salt, 'base64' => $hash, 'salt' => $salt, 'hex' => $hex, 'rounds' => 24]);
 }
All Usage Examples Of PHPDaemon\Core\Debug::exportBytes