php未引用的属性值


php unquoted attribute value

嗨,我正在尝试创建我的第一个REST服务,并花了一些时间阅读教程,我正在按照教程进行操作,在客户端代码中,我在一个未引用的属性值中得到了一个"="。在最后一个<li>条目之间的href行中。我看不出有什么不对。我想让这个例子发挥作用,然后为我正在研究的解决方案建立它。

<?php
/*** this is the client ***/
if (isset($_GET["action"]) && isset($_GET["id"]) && $_GET["action"] == "get_user") // if the   get parameter action is get_user and if the id is set, call the api to get the user information
{
 $user_info = file_get_contents('http://localhost/RestServer/api.php?action=get_user&id=' . $_GET ["id"]);
$user_info = json_decode($user_info, true);
// THAT IS VERY QUICK AND DIRTY !!!!!
?>
<table>
  <tr>
    <td>Name: </td><td> <?php echo $user_info["last_name"] ?></td>
  </tr>
  <tr>
    <td>First Name: </td><td> <?php echo $user_info["first_name"] ?></td>
  </tr>
  <tr>
    <td>Age: </td><td> <?php echo $user_info["age"] ?></td>
  </tr>
</table>
<a href="http://localhost/RestClient/index.php?action=get_userlist" >Return to the user list</a>
<?php
}
else // else take the user list
{
$user_list = file_get_contents('http://localhost/RestServer/api.php?action=get_user_list');
$user_list = json_decode($user_list, true);
// THAT IS VERY QUICK AND DIRTY !!!!!
?>
<ul>
<?php foreach ($user_list as $user): ?>
  <li>
    <a href=<?php echo "http://localhost/RestClient/index.php?action=get_user&id=" . $user   ["id"]  ?> alt=<?php echo "user_" . $user_["id"] ?>><?php echo $user["name"] ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php
}
?> 
<a href="<?php echo "http://localhost/RestClient/index.php?action=get_user&id=" . $user   ["id"]  ?>" alt="<?php echo "user_" . $user_["id"] ?>"><?php echo $user["name"] ?></a>

<a href=<?php echo "'http://localhost/RestClient/index.php?action=get_user&id=" . $user   ["id"]."'"  ?> alt=<?php echo "'user_" . $user_["id"]."'" ?>><?php echo $user["name"] ?></a>

我已经更新了您的代码,它在中运行良好

<?php echo "<a href='http://localhost/RestClient/index.php?action=get_user&id='".$user['id']."' alt=user_'".$user['id']."'>"; ?><?php echo $user["name"] . "</a>"; ?>

可能会有所帮助。

<a herf="http://localhost/RestClient/index.php?action=get_user&id="<?php echo $user["id"]; ?> alt="user_"<?php echo $user_["id"]; ?> > <?php echo $user["name"]; ?> </a>

<a herf="http://localhost/RestClient/index.php?action=get_user&id=<?php echo $user['id']; ?>" alt="user_<?php echo $user_['id']; ?>" > <?php echo $user["name"]; ?> </a>