URL参数是基于用户输入值(在$url变量中)构建的,如下所示:
$query = trim($_GET["Query"]);
if (!empty($query)) {
$url = "results.php?";
$url .= "&Query=$query";
}
$store = $_GET["Store"];
if (!empty($store)) {
$url .= "&Store=$store";
}这些URL参数(内置于$url变量中)将用于解析XML。最终将显示搜索结果。
<product category="Tablet">
<name>ipad-1</name>
<store>Best Buy</store> // problem will later occur when store element has two words
</product>
<product category="Tablet">
<name>ipad-2</name>
<store>Amazon</store>
</product>生成多个搜索结果页,并在此处创建页码链接。
for($i=0; $i<$searchResultsFound; $i++) {
if ($i == $a_condition) {
//This array below is where the probably likely is
$pageNumberLinks[] = "<a href=".$url."&firstSearchResult=".$firstSearchResultValue."&lastSearchResult=".$lastSearchResultValue.">".$pageNumberLink_i . "</a>";
}}使用这个foreach循环显示页码链接。
foreach ($pageNumberLinks as $PageNumberLinks) {
echo $PageNumberLinks . " ";
}当存储参数(从名为“store”的XML元素中提取)只有一个单词(IE Amazon),地址栏中的URL如下所示时,页面号链接工作正常:
results.php?&Query=ipad&store=Amazon&firstSearchResult=10&lastSearchResult=20但是,当存储参数有两个单词(IE )时,URL只显示第一个单词'Best‘,并切断地址栏中URL的其余部分,如下所示:
results.php?&Query=ipad&store=Best源代码如下所示:
<a href=results.php?&Query=ipad&store=Best&firstSearchResult=10&lastSearchResult=20>2</a>我的猜测是,当插入上述for循环中的数组时,页码链接没有正确编码。有没有人注意到这里有什么不正确的编码:
$pageNumberLinks[] = "<a href=".$url."&firstSearchResult=".$firstSearchResultValue."&lastSearchResult=".$lastSearchResultValue.">".$pageNumberLink_i . "</a>";顺便提一句,URL在编写如下代码时工作得很好:
<a href="<?php echo $url; ?>&Store=<?php echo $store; ?>">Anchor text</a>发布于 2014-04-29 14:53:04
您需要使用urlencode或http_build_query来简化生活。仍然检查哪些参数格式正确,但使用以下函数之一构建实际查询
检查这两个功能的手册页,并决定哪一个更适合您的需要。
https://stackoverflow.com/questions/23364177
复制相似问题