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

  • Home
  • SEARCH
  • 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 9164599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:43:20+00:00 2026-06-17T14:43:20+00:00

I am stuggling to comprehend how to accomplish the following task From : http://www.example.com/main/this_dir/page.html

  • 0

I am stuggling to comprehend how to accomplish the following task “

From : http://www.example.com/main/this_dir/page.html

I would like an output of : This Dir

When using $_SERVER['REQUEST_URI'] i can get this output :

*/main/this_dir/*

I would like to now take that and strip the last string between the two /’s so i end up with

*this_dir*

I would then like to take that string and turn it into

This Dir

There is a slight complication with this too because the directory could simply be called /this/ and not /this_dir/, but it is always one or the other and the text does change whereas the words i used were merely an example.

If anyone has any suggestions, input or feedback as to how i could accomplish this task it would be greatly appreciated! I do have a vague idea of how i could strip the last directory name from the request_uri string but i would really like to know if it would even be possible to transform the string in the way that i have described, using PHP.

  • 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-17T14:43:21+00:00Added an answer on June 17, 2026 at 2:43 pm

    You can use the basename function to get the “this_dir” part, so then it’s simply a case of doing something like this:

    $directoryName = ucwords(str_replace('_', ' ', basename($_SERVER['REQUEST_URI'])));
    

    Edit

    Slightly more convoluted example that will work for pages such as “/main/this_dir/something.php”:

    $directoryName = ucwords(str_replace('_', ' ', basename(substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/')))));
    

    This is just stripping anything after the final “/” before passing to basename to ensure it’ll work as before. Note that this will NOT work though for URLs without a trailing “/” such as “/main/this_dir” – in this case it would output “Main”.

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

Sidebar

Related Questions

Struggling with onchange for JQuery Datetime plugin: http://plugins.jquery.com/project/datetime I am using the following code.
Struggling to parse this JSON response from http://api.twitter.com/1/trends/current.json using foreach ($json_output->trends[0] as $trend )
I´m struggling to understand this concept: I have a fixed size definition: (from http://msdn.microsoft.com/pt-br/library/aa931918.aspx
I would like to update a list item using SharePoint and am stuggling to
I am trying to upgrade to cedar / asset pipeline and am stuggling with
I am trying to understand function pointers and am stuggling. I have seen the
struggling a bit to get the following to work : I'm trying to merge
Struggling with the following problem. I have an attribute that defines the name of
Struggling with the following SQL problem. Assume a three dimensional table with entries (h,t,q)
Struggling a bit today. I have the following method that returns a list of

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.