Php 在不离开当前页面的情况下更改语言

Php 在不离开当前页面的情况下更改语言,php,Php,我正在尝试更改语言,但仍停留在当前页面: i、 e: www.myurl.com/english/aboutus.php www.myurl.com/derman/aboutus.php www.myurl.com/french/aboutus.php 因此,只有语言目录更改。 我有以下功能,但无法正常工作: <?php $full_url = $_SERVER['FULL_URL'] ; $temparray = explode(".com/",$full_url,2); $

我正在尝试更改语言,但仍停留在当前页面: i、 e:

www.myurl.com/english/aboutus.php

www.myurl.com/derman/aboutus.php

www.myurl.com/french/aboutus.php

因此,只有语言目录更改。 我有以下功能,但无法正常工作:

<?php 
$full_url = $_SERVER['FULL_URL'] ;  

$temparray = explode(".com/",$full_url,2); 

$englishtemp = $temparray[0] . ".com/english/" . $temparray[1]; 
$englishlink = "<a href=$englishtemp><img src=../images/english-flag.jpg></a>"; 

echo $englishlink; 
?>

我将url从“/french/aboutus.php”更改为“/english”,但它不记得页面名“aboutus.php”,并返回到索引页面

请任何人帮忙好吗?

对当前页面使用
basename($\u SERVER['PHP\u SELF')

$englishtemp = "/english/" . basename($_SERVER['PHP_SELF']); 
$englishlink = "<a href=$englishtemp><img src=../images/english-flag.jpg></a>";
echo $englishlink;
$englishtemp=“/english/”。basename($_服务器['PHP_SELF']);
$englishlink=“”;
echo$englishlink;

请参阅。

试试这个。它将为除当前所选语言之外的所有语言生成链接:)


您尝试了什么?你研究过ajax吗?即便如此,无论如何,也许你最好还是刷新一下页面。这有什么不对?编辑了问题。让它更清楚一点。谢谢安东尼,它很有效只需从第一个链接中删除“$\u SERVER['SERVER\u NAME']”位,因为它复制了URL-再次感谢@dave编辑了答案以删除
$\u SERVER['SERVER\u NAME']
。在我个人看来,我不喜欢在域名中使用url,最好只使用绝对路径(url以a/开头),但这取决于你:)看起来更干净:)谢谢Ignas-感谢你花时间这么做,Antonys的解决方案在这个场合对我有效,但你的看起来也不错!再次感谢!
<?php
$full_url = $_SERVER['REQUEST_URI']; //select full url without the domain name
$languages = array('english', 'french', 'german'); //array of all supported languages

$url_bits = explode('/', $full_url); //divide url into bits by /
$current_language = $url_bits[1]; //current language is held in the second item of the array

//find current language in the array and remove it so we wouldn't have to display it
unset($languages[array_search($current_language, $languages)]);

$links = '';

foreach ($languages as $language) {
    //generate links with images for the rest of the languages
    $links .= '<a href="/' . $language . '/' . $url_bits[2] . '"><img src="../images/' . $language . '-flag.jpg" title="'.ucfirst($language).'" /></a>';
}

echo $links;
?>