3zzy 3zzy - 1 month ago 15
PHP Question

Getting base path in URL

code:

$url = 'https://www.example.com/path/to/product/filename.html';
echo parse_url($url);


output:

[scheme] => https
[host] => www.example.com
[path] => /path/to/product/filename.html


How do I get the current base path, that is:

https://www.example.com/path/to/product/

Answer

Easy

$basePath = dirname($url) . '/';

Demo ~ https://3v4l.org/XGNDd