doufeng1249
2014-08-29 03:30 阅读 108
已采纳

如何在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..!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    droirqk4795 droirqk4795 2014-08-29 03:37

    Try to use dirname()

    <?php
        echo "http://$_SERVER[HTTP_HOST]".dirname($_SERVER[REQUEST_URI])."/paypal_success.php";
    ?>
    
    点赞 评论 复制链接分享
  • duan0065626385 duan0065626385 2014-08-29 04:13

    $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

    点赞 评论 复制链接分享

相关推荐