Skip to content Skip to sidebar Skip to footer

Get File Name For Url 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/

Solution 1:

I think this is what you want:

<?php$page = basename($_SERVER['PHP_SELF']);
?><divid="language"><ahref="../../<?phpecho$page;?>"class="lang">EN</a><aclass="lang"href="<?phpecho$page;?>">DE</a><aclass="lang"href="../pl/<?phpecho$page;?>">PL</a></div>

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

Solution 2:

You should really google this stuff.

<?php basename($_SERVER['PHP_SELF']); ?>

GOOGLE

Now that you added some code, here ya go.

<divid="language"><ahref="../../<?phpecho basename($_SERVER['PHP_SELF']); ?>"class="lang">EN</a><aclass="lang"href="<?phpecho basename($_SERVER['PHP_SELF']); ?>">DE</a><aclass="lang"href="../pl/<?phpecho basename($_SERVER['PHP_SELF']); ?>">PL</a></div>

FYI, basename($_SERVER['PHP_SELF']); get's the name of the current file and returns just that. In other words, it will return "index.php" or "works.php"

Post a Comment for "Get File Name For Url Php"