URLS的其他元素?

时间:2013-07-25 11:34:02

标签: php tag-it

我不确定这个术语是什么,但基本上我有一个使用“tag-it”系统的网站,目前你可以点击标签,这需要用户

topics.php?tags=example

我的问题是能够添加其他链接需要什么样的脚本或编码?

topics.php?tags=example&tags=example2

topics.php?tags=example+example2

以下是我的网站如何链接到代码的代码。

header("Location: topics.php?tags={$t}");

<a href="topics.php?tags=<?php echo $fetch_name->tags; ?>"><?php echo strtolower($fetch_name->tags);?></a>

感谢任何提示或提示。

2 个答案:

答案 0 :(得分:4)

虽然您可以将其作为数组传递

,但您无法将标记作为GET参数传递两次
topics.php?tags[]=example&tags[]=example2

假设这是你想要的尝试

$string = "topics.php?";
foreach($tags as $t)
{
    $string .= "tag[]=$t&";
}
$string = substr($string, 0, -1);

我们遍历数组连接值到$ string。最后一行删除了额外的&amp;在最后一次迭代后出现的符号

还有另一个看起来更脏的选项,但根据您的需要可能会更好

$string = "topics.php?tag[]=" . implode($tags, "&tag[]=");

注意只需确保标记数组不为空

答案 1 :(得分:0)

  

topics.php?tags=example&tags=example2
  将在后端突破;

您必须将数据分配给一个变量:

topics.php?tags=example+example2

看起来不错,您可以通过+符号在后端explode访问它:

//toplics.php
<?php
    ...
    $tags = urlencode($_GET['tags']);
    $tags_arr = explode('+', $tags); // array of all tags

    $current_tags = ""; //make this accessible in the view;
    if($tags){
         $current_tags = $tags ."+"; 
    }
   //show your data
?>

编辑: 你可以创建fron-end标签:

<a href="topics.php?tags=<?php echo $current_tags ;?>horror">
    horror
</a>