PHP url变量给出空白结果

时间:2016-08-04 12:51:01

标签: php get urlvariables

我正在尝试使用URL GET将变量传递给PHP页面,但是我得到了空格,出了什么问题?!

url: http://localhost:2651/index_main.php?teamName=Liverpool

这是目标PHP文件:

<?php
  $teamName = $_GET['teamName'];
?>
<html>
<body>
<?php
$searchQuery = $api->searchTeam(urlencode('<?php $_GET["teamName"]; ?>')) // here must get the team name from previous page
?>
<h3>All home matches of <?php echo $team->_payload->name; ?>:</h3>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

首先,你的代码不干净,你使用太多的php标签。现在是您的代码:

<html>
<head>

</head>
<body>
    <?php
    $teamName = $_GET['teamName'];
    $searchQuery = $api->searchTeam(urlencode($teamName)); // here must get the team name from previous page
    ?>
    <h3>All home matches of <?php echo $team->_payload->name; ?>:</h3>
</body>
</html>

其次,在你的urlencode中,你添加了额外的php标签,而你没有使用之前设置的变量。