How to remove last part of url in PHP
There is no need to use explode
, implode
, and array_pop
.
Just use dirname($path)
. It's a lot more efficient and cleaner code.
Try this:
$url = explode('/', 'http://www.brightknowledge.org/knowledge-bank/media/studying-media/student-media/image_rhcol_thin');
array_pop($url);
echo implode('/', $url);