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 8049105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:41:31+00:00 2026-06-05T06:41:31+00:00

I am having a slight trouble. I am wanting to get a find the

  • 0

I am having a slight trouble. I am wanting to get a find the top level folder and use it as a variable.

For instance.

If I have a url: http://www.someurl.com/foldername/hello.php

I would like to look at the URL and echo ‘foldername’.

At present my code strips things so that it echos ‘hello.php’.

Any help would be greatly appreciated.

<?php

// Get URL String // 
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

// Split String and get folder//

function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/"));
}

// Pass along Results //
$foldername = curPageName();

echo $foldername;

?>
  • 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-06-05T06:41:33+00:00Added an answer on June 5, 2026 at 6:41 am
              <?php 
    
                $a = "http://www.someurl.com/foldername/hello.php";
    
                $b =  explode('/',$a);
    
                //var_dump($b); 
    
            // i got this result  array(5) { [0]=> string(5) "http:" [1]=> string(0) "" [2]=>                  string(15) "www.someurl.com" [3]=> string(10) "foldername" [4]=> string(9) "hello.php" }
    

    // now to get or echo foldername store the value from the array in a variable

             $value = $b['3'];
    
            echo $value // will output foldername 
          ?>
    

    i am a newbie too

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a slight Javascript issue at the moment, I am hoping to have the
UPDATE : look at the demo here: http://amit-verma.com/template_test/ i am having a slight problem
I'm still new to programming in excel and I am having trouble making slight
I am using FancyBox and I am having a slight problem. I have a
I have set up REST for my CakePHP and I'm having a slight problem.
I'm having a slight problem. I have set my <input type=file> to onChange=this.form.submit() .
I'm having a slight problem merging multiple transparent pngs on top of each other.
I am having a slight issue with the use of ValidationSummary(true) to display model
I am having a slight issue with my nav bar that I cant get
I have a slight problem. Having recently migrated on Mac, I've been pulling my

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.