Forum Moderators: coopster
example.com/subdir/en/widgets.php
I would like to generate a link on that page to:
example.com/subdir/fr/widgets.php
What would be the simplest way of going about this?
Many thanks for your help!
$whereami = $_SERVER['PHP_SELF'];
if (strpos($whereami,'/en/') === false) {
$reppath = "/en/";
$oldpath = "/fr/";
} else {
$reppath = "/fr/";
$oldpath = "/en/";
}
str_replace($reppath,$oldpath,$whereami);
echo "<a href=\"$whereami\">Switch Language</a>";
I think that's right, it's early here and I am un caffeinated. ;)
$whereami = $_SERVER['PHP_SELF'];
if (strpos($whereami,'/en/') === false) {
$reppath = "/\/en\//";
$oldpath = "/\/fr\//";
} else {
$reppath = "/\/fr\//";
$oldpath = "/\/en\//";
}
str_replace($reppath,$oldpath,$whereami);
echo "<a href=\"$whereami\">" . ($reppath=="/\/fr\//"?"Changez La Langue":"Switch Language") . "</a>";
str_replace($reppath,$oldpath,$whereami); should read:
str_replace($oldpath,$reppath,$whereami); Escaping the slashes didn't seem to work when I tried it, unless they were escaped in the original string...
Of course, I see this as your way of forcing me to understand what I'm doing rather than copying and pasting (you succeeded)!
I'm still waiting for the day whan I can answer one of the questions in this forum, but I'm getting better ;)