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



我正在尝试使用 string从 CC_1中删除最后几个字符。

我有字符串"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)  ;

给出

Scryed (download torrent) - TPB
Scry

为什么?预期输出为

Scryed (download torrent) - TPB
Scryed

这是因为rtrim的第二个参数是 list of carne 。不是要修剪的字符串!您应该使用substrstr_replace

$title =  substr($title_t, 0, strlen($title_t) - strlen("(download torrent) - TPB"));

$title = str_replace("(download torrent) - TPB", "" , $title_t);

最新更新