为什么rtrim删除更多的字符,并给出奇怪的输出?

AMB*_*AMB 0 php character-trimming

我试图从string使用中删除最后几个字符rtrim.

我有字符串 "Scryed (download torrent) - TPB"

我想要输出字符串 "Scryed"

例如

$title_t = "Scryed (download torrent) - TPB";

echo ($title_t)  ;
echo "\n";
$title =  ( rtrim ($title_t, "(download torrent) - TPB") );

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

Scryed (download torrent) - TPB
Scry
Run Code Online (Sandbox Code Playgroud)

这是为什么 ?预期产量是

Scryed (download torrent) - TPB
Scryed
Run Code Online (Sandbox Code Playgroud)

Mar*_*arc 6

这是因为rtrim第二个参数是字符列表.不是要修剪的字符串!你应该使用substrstr_replace:

$title =  substr($title_t, 0, strlen($title_t) - strlen("(download torrent) - TPB"));
Run Code Online (Sandbox Code Playgroud)

要么

$title = str_replace("(download torrent) - TPB", "" , $title_t);
Run Code Online (Sandbox Code Playgroud)