Asked  7 Months ago    Answers:  5   Viewed   32 times

This seems like a common questions but none of them seem to be what i'm looking for. If there is a website:

www.example.com/test.php

I want to pull the test.php and if it's something like:

www.example.com/folder/folder1/test.php

I want again to just pull test.php but everything seems to pull the exact path instead of just the page. Any suggestions?

 Answers

24
$query = $_SERVER['PHP_SELF'];
$path = pathinfo( $query );
$what_you_want = $path['basename'];

Voila.

Wednesday, March 31, 2021
 
jcubic
answered 7 Months ago
46

You can use parse_url();

$url = 'http://www.mydomain.com/abc/';

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH);

which would give you

Array
(
    [scheme] => http
    [host] => www.mydomain.com
    [path] => /abc/
)
/abc/

Update: to get current page url and then parse it:

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;
}

print_r(parse_url(curPageURL()));

echo parse_url($url, PHP_URL_PATH);

source for curPageURL function

Wednesday, March 31, 2021
 
commonpike
answered 7 Months ago
39

From the reference:

<?php

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;
}
?>
Wednesday, March 31, 2021
 
iftheshoefritz
answered 7 Months ago
86

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
 
ojrac
answered 7 Months ago
79

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
 
Nate
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :