I am trying to strip filename.extension from my local domain
local domain virtual host: http://cms.local/
and on str_replace I am trying to remove index.php
to keep it dynamic my main concern is to consider the fact that filename.extension
could be anything.
my code to do so:
private static function removeFilename($url) {
$file_info = pathinfo($url);
return isset($file_info['extension']) ? str_replace($file_info['filename'] . "." . $file_info['extension'], "", $url) : $url;
}
where $url
is unparsed url based on this post.
Considering that my url is http://cms.local/index.php
everything is going smoothly but in case my url is just http://cms.local/
; without filename.extension, str_replace
function removes cms.local
as if it is the filename.extension, leaving just http:///
.
Thanks you in advance!