[英]Echo Dynamic ascii string in PHP
I have a dynamic value $input that represents a character in ascii.我有一个动态值 $input 表示 ascii 中的一个字符。 But somehow I just can't print it out correctly.
但不知何故,我无法正确打印出来。
$str= "\155\155";
echo 'value is '.$str;
$input = 155;
$num= "\\".$input."\\".$input;
echo 'another value '.$num;
The first line will be "mm" But the second line is "\\155\\155" Is there some conversion I am leaving out?第一行是“mm” 但第二行是“\\155\\155” 有没有我遗漏的转换?
Yep.是的。 155 is octal value to m.
155 是八进制值到 m。
Check it out:一探究竟:
$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;
I'm not sure if you can do it straightforward.我不确定你是否能做到直截了当。 An easy way to reach what you want can be something like this:
达到您想要的东西的简单方法可能是这样的:
$input = 155;
$num= "\\".$input."\\".$input;
$num = str_replace("\\".$input, chr(octdec($input)), $num);
echo 'another value '.$num;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.