3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $server_path = "/test1/test2/"; echo rtrim($server_path , '/');echo "\n\n"; $server_path = str_replace(array('/', '\\'), '/', $server_path); var_dump($server_path); $next_server_path = substr($server_path, 0, strrpos($server_path, '/')); var_dump($next_server_path); echo "\n\n"; $server_path = "/test1/test2"; echo rtrim($server_path , '/');echo "\n\n"; $server_path = str_replace(array('/', '\\'), '/', $server_path); var_dump($server_path); $next_server_path = substr($server_path, 0, strrpos($server_path, '/')); var_dump($next_server_path); echo "\n\n"; $server_path = "/test1"; $server_path = str_replace(array('/', '\\'), '/', $server_path); var_dump($server_path); $next_server_path = substr($server_path, 0, strrpos($server_path, '/')); var_dump($next_server_path); echo "\n\n"; $server_path = ""; $server_path = str_replace(array('/', '\\'), '/', $server_path); var_dump($server_path); $next_server_path = substr($server_path, 0, strrpos($server_path, '/')); var_dump($next_server_path);
based on CUNdq
Output for 7.0.0 - 7.1.0
/test1/test2 string(13) "/test1/test2/" string(12) "/test1/test2" /test1/test2 string(12) "/test1/test2" string(6) "/test1" string(6) "/test1" string(0) "" string(0) "" string(0) ""
Output for 4.3.0 - 5.6.28
/test1/test2 string(13) "/test1/test2/" string(12) "/test1/test2" /test1/test2 string(12) "/test1/test2" string(6) "/test1" string(6) "/test1" string(0) "" string(0) "" bool(false)