我正在尝试使用string
删除rtrim
中的最后几个字符。
我有字符串"Scryed (download torrent) - TPB"
我想要输出字符串"Scryed"
e.g。
$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
答案 0 :(得分:5)
这是因为rtrim
的第二个参数是字符的列表。不是要修剪的字符串!您应该使用substr
或str_replace
:
$title = substr($title_t, 0, strlen($title_t) - strlen("(download torrent) - TPB"));
或
$title = str_replace("(download torrent) - TPB", "" , $title_t);