如何在PHP中获取当前目录的链接?

I have been trying to get the current directory link and come up with something like this as:

<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]paypal_success.php"; ?>

but really that didn't work as I got the output as :

http://localhost/php-login-new/invoice.phppaypal_success.php

so really I want to trim the invoice.php from it so if you can guide me please how I can do that..it will be great..!

Try to use dirname()

<?php
    echo "http://$_SERVER[HTTP_HOST]".dirname($_SERVER[REQUEST_URI])."/paypal_success.php";
?>

$path = test/invoice.phppaypal_success.php you should use basename($path), result is invoice.phppaypal_success.php

or you can use basename($path,".html"), result is invoice.phppaypal_success

$result_path = basename($path) then you can use substr() in php

echo substr($result_path,5,-22);

Maybe this can help you