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