PHP url 变量给出空白结果

PHP url variable gives blank result

我正在尝试使用 URL GET 将变量传递到 PHP 页面,但我得到空白 space,怎么了?!

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>

首先,你的代码不干净,你使用了太多 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 标签,并且您没有使用之前刚刚设置的变量。