我需要知道在标准输出上打印时一个字符串占用了多少个“空格”。
因此,例如
<? function customlength($input) { echo $input . "(" . strlen($input) . ")\n"; } echo customlength("Stefano"); echo customlength("Stefano\t\t1"); echo str_repeat("---------+", 3) . "\n"; ?>
让我知道2字符串的长度为7和10个字符,但在stdout上它们占用了7和17个“空格”
Stefano(7) Stefano 1(10) ---------+---------+---------+
因此期望得到了
Stefano(7)
Stefano 1(17)
---------+---------+---------+
我需要知道在标准输出上打印时,一个字符串占用了多少个“空格”。因此,作为示例函数customlength($ input){echo $ input。 “(”。strlen($ input)。“)\ n”; } echo ...
制表符问题的解决方法是将它们替换为空格: