I'm still new to php and I've made a script that checks the language of the website and if it's English set's the button link to an english page and else to another page.
Here goes:
<?php
$link1 = "http://www.uvt.ro/ro/accesibilitate/";
$link2 = "http://www.uvt.ro/en/accesibilitate/";
$url = "";
if($_SESSION["lang"]->lang!="ro"){
$url = $link2;
}
else {
$url = $link1;
}
?>
<a href=".$url.">Button</a>
It's supposed to be simple, I don't know why it doesn't work.
答案 0 :(得分:3)
您echo $url
就像这样:
<?php
$link1 = "http://www.uvt.ro/ro/accesibilitate/";
$link2 = "http://www.uvt.ro/en/accesibilitate/";
$url = "";
if ($_SESSION["lang"]->lang != "ro") {
$url = $link2;
}
else {
$url = $link1;
}
?>
<a href="<?php echo $url;?>">Button</a>
您可以使用ternary operator:
将代码压缩为此<?php
$link1 = "http://www.uvt.ro/ro/accesibilitate/";
$link2 = "http://www.uvt.ro/en/accesibilitate/";
$url = ($_SESSION["lang"]->lang != "ro") ? $link2 : $link1;
?>
<a href="<?php echo $url;?>">Button</a>
答案 1 :(得分:0)
你必须在标签中回显$ url。
<a href="<?php echo $url;?>">Button</a>
答案 2 :(得分:0)
<a href=".$url.">Button</a>
替换为:
<a href="<?php echo $url; ?>">Button</a>
OR
<a href="<?=$url?>">Button</a>
答案 3 :(得分:0)
你可以尝试这个:
<?php
$test = $_GET['p'];
?>
<a href="diffdir/<?php echo $test ?>">Test</a>
或
尝试
PHP中的HTML:
echo "<a href='".$link_address."'>Link</a>";
甚至你可以试试
echo "<a href='$link_address'>Link</a>";
或者您可以在HTML中使用PHP,如
HTML中的PHP:
<a href="<?php echo $link_address;?>"> Link </a>