【发布时间】:2018-06-15 04:04:45
【问题描述】:
我正在尝试使用 PHP 的 ltrim() 删除目录的一部分,但是结果出乎意料。我的结果的第一个字母有错误的 ascii 值,并在浏览器中显示为缺少字符/框。
这是我的代码:
$stripPath = "public\docroot\4300-4399\computer-system-upgrade";
$directory = "public\docroot\4300-4399\computer-system-upgrade\3.0 Outgoing Documents";
$shortpath = ltrim($directory, $stripPath);
echo $shortpath;
预期输出:
3.0 Outgoing Documents
实际输出:
.0 Outgoing Documents
注意点之前的不可见/非打印字符。 Ascii 值从 Hex 33(数字 3)更改为 Hex 03(不可见字符)。 我也尝试了 str_replace() 而不是 trim(),但结果保持不变。
我在这里做错了什么?我将如何获得预期的结果“3.0 Outgoing Documents”?
【问题讨论】:
标签: php string str-replace trim