我正在创建PHP类别页面,我的脚本没有显示#标记和+标记,添加了类别标题示例,如我的URL Localhost。
http://localhost/zblog/category/1/2/c++和我的其他标题添加了类似以下http://localhost/zblog/category/1/3/php的类别
以下是我的代码
if(isset($_GET['srcid'])) {
$srcid = $_GET['srcid'];
$title= $_GET['title'];
}类别链接
<span class="post-category"><a href="<?php echo $url; ?>
category/1/<?php echo $row['cat_id'] ?>/
<?php echo $row['cat_title']; ?>" title="View all posts in General" rel="category tag">
<?php echo $row['cat_title']; ?></a></span>url链接
<a class="post-source" href="<?php echo $url; ?>
<?php echo 'category/'.rawurlencode($row['cat_id']).'/'.
rawurlencode($row['cat_title']);?>"><h1 class="post-title">
<?php echo $row['cat_title'] ?></h1></a> 发布于 2019-04-23 10:25:50
#是不安全的URL字符,因为它在url中有意义。它被称为fragment,与链接锚点一起使用。
+是一个安全的角色,应该没有理由它不能工作。
我建议您尝试以不同的方式解析您的URL。
$url = 'http://localhost/zblog/category/1/2/c++';
$path = parse_url($url, PHP_URL_PATH);
$categories = explode("/", str_replace("/zblog/category/", "", $path));
var_dump($categories);输出:
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(3) "c++"
}发布于 2019-04-23 04:17:35
您正在以错误的方式为PHP准备链接。此外,为了通过URL发送,您需要包含特殊字符。为了让PHP正确地解释URL并从中获取值,您需要这样做:
<span class="post-category"><a href="<?php echo $url; ?>?srcid=<?php echo 'category/1/'.rawurlencode($row['cat_id']).'/'; ?>&title=<?php echo rawurlencode($row['cat_title']); ?>" title="View all posts in General" rel="category tag">
以下是如何创建PHP链接的示例:
http://web_adress/page.php?first_param=value_of_first_param&second_param=value_of_second_param&third_param=value_of_third_param
^ ^ ^
Here you start with params Here you are telling the other one is coming 然后,您可以使用:
if(isset($_GET['first_param']) {
//Get all others or whatever
$second_param = rawurldecode($_GET['second_param']);
//Your example
$srcid = rawurldecode($_GET['srcid']);
$title = rawurldecode($_GET['title']);
}如果你能根据我在这里创建的例子调整你的代码,它将会工作。为了能够通过URL发送特殊字符,使用rawurlencode对这些字符进行编码,在另一端使用rawurldecode对它们进行解码。我在上面举了一个例子。请注意,如果您使用urlencode +符号将无法通过,并且您将获得空间。
https://stackoverflow.com/questions/55799862
复制相似问题