问题
I am trying to remove last few characters from the string using rtrim.
i have string "Scryed (download torrent) - TPB"
i want output string "Scryed"
e.g.
$title_t = "Scryed (download torrent) - TPB";
echo ($title_t) ;
echo "\n";
$title = ( rtrim ($title_t, "(download torrent) - TPB") );
echo ($title) ;
gives
Scryed (download torrent) - TPB
Scry
Why is that ? expected output is
Scryed (download torrent) - TPB
Scryed
回答1:
It's because rtrim's second parameter is list of characters. Not a string to be trimmed! You should use a substr or str_replace:
$title = substr($title_t, 0, strlen($title_t) - strlen("(download torrent) - TPB"));
or
$title = str_replace("(download torrent) - TPB", "" , $title_t);
来源:https://stackoverflow.com/questions/46307527/why-is-rtrim-removing-more-characters-and-giving-weird-output