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 new to PHP, and I can't figure out this basic question. Does PHP
Im new to PHP and I can't figure out what the rules are for
I'm new to PHP but was wondering how this can be done. I want
I am new to MySQL and PHP(as you can probably tell) and I was
I am starting a new web application in PHP and this time around I
MySQL connection in PHP can be established in two ways: $mysql = new mysqli('localhost',
I'm new to PHP and I'm following a tutorial here: Link It's pretty scary
Hi i am new in cake php and can't solve the problem. The problem
i am new to php and mysql. How can i extract a VALUE from
Has anyone ever modified the post-new.php file in their WordPress installation? I want to

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.