0

I am wondering if this is at all possible. There are lots of questions on the subject in SO, but none address this specific issue.

I have a symlink that looks like this:

reroof-for-abe-froman.php -> /var/www/yourprojects/app/project.php

Now all I want returned from a variable is reroof-for-abe-froman with, or without the extension (preferably without).

I have tried all of these:

echo basename(__FILE__, '.php') . "\n";
echo $_SERVER['REQUEST_URI'] . "\n";
echo $_SERVER['SCRIPT_FILENAME'] . "\n";
echo __FILE__ . "\n";

With the following results:

project
/project/reroof-for-abe-froman
/var/www/liveSites/websites/allseasonsny/public_html/project/reroof-for-abe-froman.php
/var/www/yourprojects/app/project.php

Now I realize I can use $_SERVER['REQUEST_URI'] and str_replace or explode to get what I want. IE:

$uri = str_replace('/project/', '',  $_SERVER['REQUEST_URI'])

Which would give the desired output. I was just wondering if there was a "cleaner" way to accomplish this without the manipulation of a _SERVER variable?

Zak
  • 6,976
  • 2
  • 26
  • 48
  • 2
    `basename($_SERVER['REQUEST_URI'])`? – Nigel Ren Oct 04 '19 at 16:40
  • https://stackoverflow.com/questions/1418193/how-do-i-get-a-file-name-from-a-full-path-with-php – EternalHour Oct 04 '19 at 16:44
  • @NigelRen I never thought to combine `basename` to `$_SERVER['REQUEST_URI']` -- I thought it would do the same thing as `basename(__FILE__, '.php')` because in the documentation it implies that it would return the original path .. Why does this work? Write in an answer and I'll accept. – Zak Oct 04 '19 at 16:45

0 Answers0