Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sytnax帮助PHP_Php_Html - Fatal编程技术网

sytnax帮助PHP

sytnax帮助PHP,php,html,Php,Html,如何正确地编写这个synax,这里我只想为配置文件创建目标链接 <a href="index.php?p=profile&uid=$_SESSION["uid"]"> $_SESSION["username"]</a> 我想在&uid=之后添加$\u会话[“uid”] 我想在标签之间添加$\u会话[“用户名”] <a href="index.php?p=profile&uid=<?php echo $_SESSION['uid'] ?>

如何正确地编写这个synax,这里我只想为配置文件创建目标链接

<a href="index.php?p=profile&uid=$_SESSION["uid"]"> $_SESSION["username"]</a>
我想在
&uid=
之后添加
$\u会话[“uid”]

我想在
标签之间添加
$\u会话[“用户名”]
<a href="index.php?p=profile&uid=<?php echo $_SESSION['uid'] ?>"> echo $_SESSION['username']</a>

您想要的是:

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

您可以这样做:

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

echo $link;
$link=sprintf(
'',
$\u会话[“uid”]=“32”,
$\u会话[“用户名”]=“metaxa”
);
echo$link;

您可以进入PHP模式并使用
echo
printf
打印文本,也可以使用速记
语法实现相同效果

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


/   
现在链接起作用了,但“if”的其他部分也起作用了

您可以
echo
使用双引号,转义内联双引号,并使用大括号+单引号访问数组元素

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

请看一看。您也可以检查.I登录并且我有活动的$\u会话[“activeuser”],但是在登录/注册div上显示了用户的名称和登录/注册按钮。您应该添加一个解释,解释为什么这可以解决问题,没有上下文的代码块本身对于其他来这里寻求帮助的用户来说不是很有用。
<?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 
echo "<a href=\"index.php?p=profile&uid={$_SESSION['uid']}\">{$_SESSION['username']}</a>";