gpt4 book ai didi

PHP rtrim 和 ltrim 的修剪比预期的要多

转载 作者:行者123 更新时间:2023-12-05 08:21:06 26 4
gpt4 key购买 nike

我想从我网站的页面中删除 Search -。下面是我的代码示例:

输入:

$search = "Search - echelon";
$trim = "Search - ";

$result = ltrim($search,$trim);


echo $result;

输出:

lon

期望输出:

梯队

我该怎么做,为什么 ltrim 在我上面的例子中修剪得更多?谢谢!

最佳答案

RTM .第二个参数被视为一组要修剪的字符。

在这种情况下:

S - in the list, trim it
e - in the list, trim it
a - in the list, trim it
r - in the list, trim it
c - in the list, trim it
h - in the list, trim it
_ - (space) in the list, trim it
- - in the list, trim it
_ - (space) in the list, trim it
e - in the list, trim it
c - in the list, trim it
h - in the list, trim it
e - in the list, trim it
l - NOT in the list, stop!

lon is left

你是这个意思吗?

$result = substr($search,strlen($trim));

关于PHP rtrim 和 ltrim 的修剪比预期的要多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23089101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com