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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:11:04+00:00 2026-06-01T20:11:04+00:00

This script should detect the last portion in the full path, and if it

  • 0

This script should detect the last portion in the full path, and if it is stackoverflow output ok

$current_url = $_SERVER['REQUEST_URI'];

$current_url_arr = explode('/',$current_url);
$count = count($current_url_arr);

if($current_url_arr[$count-2] == 'stackoverflow'){
    echo 'ok';
}
else {
    echo 'not ok';
}

Example 1: www.myserver.ext/something/else/stackoverflow/
Output: ok


Example 2: www.myserver.ext/something/else/stackoverflow
Output: not ok


Example 3: www.myserver.ext/something/else/stackoverflow/foo
Output: not ok


I hope that you understand the idea. This script works fine, but I’m wondering if there is any better, elegant way to read last portion of URL?

  • 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-01T20:11:04+00:00Added an answer on June 1, 2026 at 8:11 pm

    Yes! There’s $_SERVER['PATH_INFO']:

    if(isset($_SERVER['PATH_INFO'])) {
        $info = explode('/', trim($_SERVER['PATH_INFO'], '/'));
    
        if($info[count($info) - 1] === 'stackoverflow') {
            echo 'ok';
        } else {
            echo 'not ok';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one shell script opening a perl script. This perl script should be
This would be an example of database table: PHP script should limit query result
EDIT: My main code no longer works, should this function work? <script type=text/javascript src=jquery-1.7.2.js></script>
Can someone explain why this script throws an exception? $byteArray = @(1,2,3) write-Output (
I use the following PHP script as index for my website. This script should
When building code like this: <script type=text/javascript src=<%=ResolveUrl(~/js/js.js)%>></script> or <input type=image src=<%=ResolveUrl(~/img/submit.png)%> /> Should
This script uses jsdom and jquery to get the value of an a tag's
For this script, it checks to see if the file is a microsoft words
I have this script which basically toggles a bgColor class on and off so
I got this script called rapidshare link checker v2 php by Bigfish At the

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.