【问题标题】:Passing contents of a php variable using the URL使用 URL 传递 php 变量的内容
【发布时间】:2015-02-13 15:19:08
【问题描述】:

我想使用 URL 传递 php 变量的值,方法是使用变量名。这是我想要实现的目标的示例,它不起作用,bu 也不会崩溃,所以我知道我很接近......任何人......请:

<a href="student_what_learning_unit.php?student=<?php $student_user ?>">Unit Learning</a>

【问题讨论】:

  • 定义它不起作用
  • 当然不行你需要echo$student_user

标签: php variables url


【解决方案1】:

就我个人而言,我不喜欢将一小段 PHP 代码放入 HTML 中。可以做到,但是有问题。最好编写干净的 PHP 代码,例如:

<?php

$url = 'student_what_learning_unit.php?student='.urlencode($student_user);
echo '<a href="'.$url.'">Unit Learning</a>';

您确实需要 urlencode() 作为 URL,请参阅:

http://php.net/manual/en/function.urlencode.php

【讨论】:

  • 谢谢你,这会让我感到很舒服如果我要重新开始
【解决方案2】:

只需像这样添加echo

<a href="student_what_learning_unit.php?student=<?php echo $student_user ?>">Unit Learning</a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    相关资源
    最近更新 更多