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.
You'd echo the $url
like so:
<?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>
You can condense the code to this using the 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>
你必须在标签中回显$ url。
<a href="<?php echo $url;?>">Button</a>
<a href=".$url.">Button</a>
replace with:
<a href="<?php echo $url; ?>">Button</a>
OR
<a href="<?=$url?>">Button</a>
you can try this one:
<?php
$test = $_GET['p'];
?>
<a href="diffdir/<?php echo $test ?>">Test</a>
or
Try like
HTML in PHP :
echo "<a href='".$link_address."'>Link</a>";
Or even you can try like
echo "<a href='$link_address'>Link</a>";
Or you can use PHP in HTML like
PHP in HTML :
<a href="<?php echo $link_address;?>"> Link </a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.