【发布时间】:2014-02-16 20:52:50
【问题描述】:
我正在尝试从在 for each 循环中创建的链接传递 PHP 变量。
这是页面上生成链接和要发送的变量的代码:
$xmlDoc = simplexml_load_file("products.xml");
$storeArray = array();
foreach($xmlDoc->product as $Product) {
echo "Name: " . $Product->name . ", ";
echo "Price: " . $Product->price . ", ";
$store = (string)$Product->store;
if (!array_key_exists($store, $storeArray)) {
$storeArray[$store] = "<a href='searchResults.php?storeSearch=<?php echo $store; ?>'>" .
$store . "</a>";
}}
foreach ($storeArray as $store) {
echo $store . "<br>";
}
下面是页面上接收变量的代码: $searchByStore = $_GET["storeSearch"]; echo "商店搜索变量是:" . $searchByStore;
searchByStore 变量没有被回显。有什么建议吗?
此网址在浏览器中的显示方式如下: .../searchResults.php?storeSearch=%3C?php%20echo%20Best%20Buy;%20?%3E 而不是正常的方式,即: .../searchResults.php?storeSearch=Best%20Buy
这里是 XML 文件:
<product type="Electronics">
<name> Desktop</name>
<price>499.99</price>
<store>Best Buy</store>
</product>
<product type="Electronics">
<name>Lap top</name>
<price>599.99</price>
<store>Best Buy</store>
</product>
<product type="Hardware">
<name>Hand Saw</name>
<price>99.99</price>
<store>Lowes</store>
</product>
</products>
【问题讨论】: