Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4172254
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:32:26+00:00 2026-05-21T00:32:26+00:00

I am new in PHP and can’t figure out how to do this: $link

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T00:32:27+00:00Added an answer on May 21, 2026 at 12:32 am

    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.

    $link = 'http://www.domainname.com/folder1/folder2/folder3/folder4';
    $parts = parse_url($link);
    $pathParts = explode('/', trim($parts['path'], '/'));
    
    $buffer = "";                                                                                                                                                                                                                                                                 
    foreach ($pathParts as $part) {
        $buffer .= $part.'/';
    
        echo $buffer . PHP_EOL;
    }
    
    /*
    Output:
    
    folder1/
    folder1/folder2/
    folder1/folder2/folder3/
    folder1/folder2/folder3/folder4/
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm fairly new to PHP and can't seem to figure this one out. i've
Im new to PHP and I can't figure out what the rules are for
I am pretty new to PHP and MySQL and I just can't figure this
I have a string like this The theme song of whatever - http://www.anydomain.com/pop_new.php?sid=10623&aid=1581&rand=0.6808111508818073 #string
I'm new to PHP and I can't figure out how to deal with Instagram
I'm sure this is pretty elementary but I'm new to php. Can someone tell
EDIT: Yields that there is already new PHP framework written as extension. http://code.google.com/p/yafphp ,
I'm new to PHP, and have spent 10 hours trying to figure this problem
There is a page that I'm currently working on ( http://www.flcbranson.org/freedownloads-new.php ) that loads
MySQL connection in PHP can be established in two ways: $mysql = new mysqli('localhost',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.