I am new in PHP and can’t figure out how to do this:
$link = 'http://www.domainname.com/folder1/folder2/folder3/folder4';
$domain_and_slash = http://www.domainname.com . '/';
$address_without_site_url = str_replace($domain_and_slash, '', $link);
foreach ($folder_adress) {
// function here for example
echo $folder_adress;
}
I can’t figure out how to get the $folder_adress.
In the case above I want the function to echo these four:
- folder1
- folder1/folder2
- folder1/folder2/folder3
- folder1/folder2/folder3/folder4
The $link will have different amount of subfolders…
This gets you there. Some things you might explore more: explode, parse_url, trim. Taking a look at the docs of there functions gets you a better understanding how to handle url’s and how the code below works.