0

我正在尝试从stringusing中删除最后几个字符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)  ;

Scryed (download torrent) - TPB
Scry

这是为什么 ?预期输出是

Scryed (download torrent) - TPB
Scryed
4

1 回答 1

6

这是因为rtrim' 的第二个参数是字符列表。不是要修剪的字符串!您应该使用substror str_replace

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

或者

$title = str_replace("(download torrent) - TPB", "" , $title_t);
于 2017-09-19T18:37:53.233 回答