AMB*_*AMB 0 php character-trimming
我试图从string使用中删除最后几个字符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) ;
Run Code Online (Sandbox Code Playgroud)
给
Scryed (download torrent) - TPB
Scry
Run Code Online (Sandbox Code Playgroud)
这是为什么 ?预期产量是
Scryed (download torrent) - TPB
Scryed
Run Code Online (Sandbox Code Playgroud)
这是因为rtrim第二个参数是字符列表.不是要修剪的字符串!你应该使用substr或str_replace:
$title = substr($title_t, 0, strlen($title_t) - strlen("(download torrent) - TPB"));
Run Code Online (Sandbox Code Playgroud)
要么
$title = str_replace("(download torrent) - TPB", "" , $title_t);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
68 次 |
| 最近记录: |