PHP rtrim和ltrim正在修剪超过预期

JCB*_*gar 1 php

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

输入:

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

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


echo $result;
Run Code Online (Sandbox Code Playgroud)

输出:

lon

欲望输出:

echelon

我怎么能这样做,为什么ltrim会在上面的例子中修剪掉更多?谢谢!

Nie*_*sol 6

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
Run Code Online (Sandbox Code Playgroud)

你的意思是?

$result = substr($search,strlen($trim));
Run Code Online (Sandbox Code Playgroud)