Reputation:
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
Upvotes: 1
Views: 339
Reputation: 581
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);
Upvotes: 7