PHP中的Echo Dynamic ascii字符串

时间:2017-10-07 05:25:37

标签: php string ascii

我有一个动态值$ input表示ascii中的一个字符。但不知何故,我无法正确打印出来。

b'https://cws004.gear3rd.net/files/videos/2017/10/02/1506885868406f9-240.mp4?h=RMw7hU2eU5jydDpg5dnzPw&ttl=1507078656'

第一行将是" mm" 但第二行是" \ 155 \ 155" 我遗漏了一些转换吗?

1 个答案:

答案 0 :(得分:1)

是的。 155是八进制值到m。

检查出来:

$str= "\155\155";
echo 'value is '.$str;

$input = 155;
$num = octdec($input);
$num = chr($num);
echo ' another value from octal '.$num;

$input = 109;
$num = chr($input);
echo ' another value from decimal '.$num;

我不确定你能否直截了当地做到这一点。达到你想要的东西的简单方法可以是这样的:

$input = 155;
$num= "\\".$input."\\".$input;
$num = str_replace("\\".$input, chr(octdec($input)), $num);
echo 'another value '.$num;