2017-04-11 92 views
-2

如何正确地写这个synax,这里只是我要让目标链接,资料...sytnax帮助PHP

<a href="index.php?p=profile&uid=$_SESSION["uid"]"> $_SESSION["username"]</a> 

我的变量是:

$_SESSION["uid"] ="32"; 
$_SESSION["username"] = "metaxa"; 

我想以后添加$_SESSION["uid"]&uid=

,我想添加标签

<a></a>之间10
+0

请看看[从HTML转义](http://php.net/manual/en/language.basic-syntax.phpmode.php)。你也可以检查[字符串参考](http://php.net/manual/en/language.types.string.php)。 –

+0

回答

1
<a href="index.php?p=profile&uid=<?php echo $_SESSION['uid'] ?>"> echo $_SESSION['username']</a> 
+0

为了解决这个问题,你应该添加一个解释,一个代码块本身没有上下文对于其他用户来这里寻找帮助并不是非常有用。 – Adam

1

你想要的东西,如:

<a href="index.php?p=profile&uid=<?php echo $_SESSION['uid']; ?>"> <?php echo $_SESSION['username']; ?></a> 
0

你可以做这样的事情:

$link = sprintf(
    '<a href="index.php?p=profile&uid=%s">%s</a>', 
    $_SESSION["uid"] ="32", 
    $_SESSION["username"] = "metaxa" 
); 

echo $link; 
0

您可以进入PHP模式,并使用echoprintf打印的文本,或者你可以使用简写<?= ... ?>语法来获得相同的效果。

<a href="index.php?p=profile&uid=<?= $_SESSION["uid"] ?>"><?= $_SESSION["username"] ?></a> 
0
<?php if (@$_SESSION["activeuser"]) { ?> 
      <a href="index.php?p=profile&uid=<?php echo $_SESSION['userid']; ?>"> <?php echo $_SESSION["username"]; ?></a> 

     <?php} 
     else { ?> 
     <a href="index.php?p=login">Login</a> &nbsp;/&nbsp; <a href="index.php?p=joinus">Join us</a> 
     <?php } ?> </div>  

Now the link is working, but else part of the `if` is working also 
+0

我登录后,我有活跃的$ _SESSION [“activeuser”],但在登录/注册div显示用户名和登录/注册按钮.. –

0

可以echo加上双引号,逃生内嵌双引号,并使用大括号+单引号来访问数组元素。

echo "<a href=\"index.php?p=profile&uid={$_SESSION['uid']}\">{$_SESSION['username']}</a>";