rtrim function doesn't work with ending h letter

前端 未结 5 826
感动是毒
感动是毒 2021-01-26 04:26
$file = \"refinish.php\";
$folder = rtrim($file, \".php\");
echo $folder; // refinis

where is ending h ?

I tried with some other

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-26 05:05

    rtrim() does not remove the string you specify in the second argument, but all characters in that string. In your case, that includes "h".

    What you need here is a simple str_replace():

    $folder = str_replace('.php', '', $file);
    

    Edit: if you want to make sure it strips the ".php" part only from the end of the $file, you can go with @racetrack's suggestion below and use preg_replace() instead:

    $folder = preg_replace('/\.php$/', '', $file);
    

提交回复
热议问题