Php URL的附加元素?
我不确定术语是什么,但基本上我有一个使用“tag it”系统的网站,目前你可以点击标签,它会让用户Php URL的附加元素?,php,tag-it,Php,Tag It,我不确定术语是什么,但基本上我有一个使用“tag it”系统的网站,目前你可以点击标签,它会让用户 topics.php?tags=example 我的问题是,需要什么样的脚本或编码才能添加额外的链接 topics.php?tags=example&tags=example2 或 下面是我的网站如何链接到标签的代码 header("Location: topics.php?tags={$t}"); 或 谢谢你的提示和提示 topics.php?tags=example&tags
topics.php?tags=example
我的问题是,需要什么样的脚本或编码才能添加额外的链接
topics.php?tags=example&tags=example2
或
下面是我的网站如何链接到标签的代码
header("Location: topics.php?tags={$t}");
或
谢谢你的提示和提示
topics.php?tags=example&tags=example2
将在后端中断 您必须将数据分配给一个变量:
topics.php?tags=example+example2
看起来不错您可以通过+
符号在后端访问它:
//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
?>
//toplics.php
编辑:
可以创建前端标记:
<a href="topics.php?tags=<?php echo $current_tags ;?>horror">
horror
</a>
topics.php?tags=example&tags=example2
将在后端中断 您必须将数据分配给一个变量:
topics.php?tags=example+example2
看起来不错您可以通过+
符号在后端访问它:
//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
?>
//toplics.php
编辑:
可以创建前端标记:
<a href="topics.php?tags=<?php echo $current_tags ;?>horror">
horror
</a>
虽然可以将标记作为数组传递,但不能将其作为GET参数传递两次
topics.php?tags[]=example&tags[]=example2
假设这是你想要的,试试看
$string = "topics.php?";
foreach($tags as $t)
{
$string .= "tag[]=$t&";
}
$string = substr($string, 0, -1);
我们遍历数组,将值连接到$string。最后一行删除将在最后一次迭代后显示的额外符号(&S)
还有另一个选项,看起来有点脏,但根据您的需要可能更好
$string = "topics.php?tag[]=" . implode($tags, "&tag[]=");
注意只需确保标记数组不为空您不能将标记作为GET参数传递两次,尽管您可以将其作为数组传递
topics.php?tags[]=example&tags[]=example2
假设这是你想要的,试试看
$string = "topics.php?";
foreach($tags as $t)
{
$string .= "tag[]=$t&";
}
$string = substr($string, 0, -1);
我们遍历数组,将值连接到$string。最后一行删除将在最后一次迭代后显示的额外符号(&S)
还有另一个选项,看起来有点脏,但根据您的需要可能更好
$string = "topics.php?tag[]=" . implode($tags, "&tag[]=");
注意只需确保标记数组不为空如果我没记错的话,我不确定加号是否是一个好的选择,它是一个特殊的url字符。是的,加号是一个特殊的url字符,用于空格:)谢谢你的帖子,我已经用$\u GET['tags']部分设置了它,我唯一的困惑是这样做,如果我有电影恐怖作为标签,我可以在“电影”,然后点击“恐怖”,它添加到URL。我以+为例,正如我所看到的那样,使用该系统。+符号很好,因为它使url在当前场景中更具可读性,您始终可以在后端对其进行解码。我不确定加号是否是一个好的选择,如果我没记错的话,它是一个特殊的url字符。是的,加号是空白处的一个特殊url字符:)谢谢你的帖子,我已经用$_GET['tags']部分设置了它,我唯一的困惑是这样做的,如果我有电影恐怖作为标记,我可以在“电影”上,然后点击“恐怖”并将其添加到url。我以+为例,正如我所看到的那样,使用该系统。+符号很好,因为它使url在当前场景中更具可读性,您始终可以在后端对其进行解码。这就是我将要发布的内容构建这样一个url查询字符串的“正确”方法是使用:
http\u build\u query(array('tags'=>array('example-tag-1','example-tag-2'));
谢谢这个方便的函数,可惜我以前从未遇到过它这就是我要发布的内容构建这样一个URL查询字符串的“正确”方法是使用:http\u build\u query(array('tags'=>array('example-tag-1','example-tag-2'))
谢谢你的便利功能,可惜我以前从未遇到过