本文介绍了PHP rtrim和ltrim的修剪比预期的要多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的网站页面上删除Search -.这是我下面的代码示例:

Im wanting to remove the Search - from a page on my website. Here is an example of my code below:

输入:

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

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


echo $result;

输出:

lon

需求输出:

echelon

我该怎么做?为什么在上面的示例中ltrim会减少更多?谢谢!

How can I do this, and why does ltrim trim off more in my example above? Thanks!

推荐答案

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

RTM. The second argument is treated as a set of characters to trim.

在这种情况下:

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的修剪比预期的要多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 09:29