This question looks pretty easy (and probably it is), but I am stuck with the following scenario: I'm using XAMPP and have several Joomla installations in subfolders such as \joomla3, \joomla4, etc. I want to check if a given file is in the folder 'images' and if the folder 'images' is a subfolder of root. Following code is from a plugin written in PHP:
$uri = Uri::getInstance();
$base = $uri->base();
$base is 'https://localhost/Joomla3/'
From given URLs like:
$src = '/Joomla3/images/foo/bar.webp'
$src = 'https://localhost/joomla3/images/foo/bar2.png'
Following code
$uri2 = Uri::getInstance($src);
$path = $uri2->getPath();
returns:
/Joomla3/images/foo/bar.webp
/joomla3/images/foo/bar2.png
The returned value of getPath is starting with the subfolder of the installation, so in order to check if 'images' is in the root I have to use some regex probably to exclude '/Joomla3/'. Is there a more elegant way to have the following returns:
/images/foo/bar.webp
/images/foo/bar2.png
Having them is easy to check if the path starts with '/images/'.