获取URL PHP的文件名 [英] get file name for url php

查看:70
本文介绍了获取URL PHP的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在PHP中获取当前文件名,以便能够将同一文件加载到其他目录中.

I wanted to know how to get the current file name in PHP to be able to load the same file in a different directory.

index.php
works.php

lang/de/
   index.php
   works.php
lang/pl/
   index.php
   works.php

<div id="language">
    <a href="../../index.php" class="lang">EN</a>
    <a class="lang" href="index.php">DE</a>
    <a class="lang" href="../pl/index.php">PL</a>
</div>

当前方法是将lang URL重定向,始终重定向到index.php.我很想知道如何从Works.php重定向到lang/de/works.php,而无需重定向到lang/de/index.php

The current method is redirecting the lang URL, allways to index.php. I would love to know how to redirect from works.php to lang/de/works.php without redirecting to lang/de/index.php

对不起,如果我让您感到困惑

Sorry if i'm getting you confused

推荐答案

我认为这是您想要的:

<?php

$page = basename($_SERVER['PHP_SELF']);
?>

<div id="language">
    <a href="../../<?php echo $page;?>" class="lang">EN</a>
    <a class="lang" href="<?php echo $page;?>">DE</a>
    <a class="lang" href="../pl/<?php echo $page;?>">PL</a>
</div>

您将当前文件名保存在$ page变量中.然后回显它,并替换链接中的index.php.

You would save the current file name in the $page variable. Then echo it out and replace index.php in your links.

这篇关于获取URL PHP的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆