rtrim function doesn't work with ending h letter

前端 未结 5 867
感动是毒
感动是毒 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 04:49

    How rtrim() works

    $file = "finish.php";
    $folder = rtrim($file, ".php");
    

    is processed working through the characters in $file from the last character backwards as

    $file = "finish.php";
    //                ^
    //     Is there a `p` in the list of characters to trim
    
    $folder = rtrim($file, ".php");
    //                       ^
    //     Yes there is, so remove the `p` from the `$file` string
    
    $file = "finish.ph";
    //               ^
    //     Is there a `h` in the list of characters to trim
    
    $folder = rtrim($file, ".php");
    //                        ^
    //     Yes there is, so remove the `h` from the `$file` string
    
    $file = "finish.p";
    //              ^
    //     Is there a `p` in the list of characters to trim
    
    $folder = rtrim($file, ".php");
    //                       ^
    //     Yes there is, so remove the `p` from the `$file` string
    
    $file = "finish.";
    //             ^
    //     Is there a `.` in the list of characters to trim
    
    $folder = rtrim($file, ".php");
    //                      ^
    //     Yes there is, so remove the `.` from the `$file` string
    
    $file = "finish";
    //            ^
    //     Is there a `h` in the list of characters to trim
    
    $folder = rtrim($file, ".php");
    //                        ^
    //     Yes there is, so remove the `h` from the `$file` string
    
    $file = "finis";
    //           ^
    //     Is there a `s` in the list of characters to trim
    
    $folder = rtrim($file, ".php");
    //                      ????
    //     No there isn't, so terminate the checks and return the current value of `$file`
    
    $file = "finis";
    

提交回复
热议问题