问题描述
Wordpress提供了一个名为"the_permalink()"的函数,您可以猜到它!它在帖子循环中返回给定帖子的永久链接.
Wordpress provides a function called "the_permalink()" that returns, you guessed it!, the permalink to a given post while in a loop of posts.
我正在尝试对永久链接进行URL编码,并且在执行以下代码时:
I am trying to URL encode that permalink and when I execute this code:
<?php
print(the_permalink());
$permalink = the_permalink();
print($permalink);
print(urlencode(the_permalink()));
print(urlencode($permalink));
$url = 'http://wpmu.local/graphjam/2008/11/06/test4/';
print($url);
print(urlencode($url));
?>
它在HTML中产生以下结果:
it produces these results in HTML:
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http%3A%2F%2Fwpmu.local%2Fgraphjam%2F2008%2F11%2F06%2Ftest4%2F
我希望输出的第2、3和5行经过URL编码,但只有第5行是URL编码.有想法吗?
I would expect lines 2, 3 and 5 of the output to be URL encoded, but only line 5 is so. Thoughts?
推荐答案
根据文档, the_permalink
打印永久链接vs并将其返回.因此,urlencode
没有任何要编码的东西.
According to the docs, the_permalink
prints the permalink vs returns it. So, urlencode
isn't getting anything to encode.
尝试 get_permalink
.
[ EDIT ]
进行编辑有点晚了,但是我没有意识到打印计数是一个问题.
A little late for an edit, but I didn't realize the print counts were such an issue.
他们都是从这里来的:
<?php
print(the_permalink()); // prints (1)
$permalink = the_permalink(); // prints (2)
print($permalink); // nothing
print(urlencode(the_permalink())); // prints (3)
print(urlencode($permalink)); // nothing
$url = 'http://wpmu.local/graphjam/2008/11/06/test4/';
print($url); // prints (4)
print(urlencode($url)); // prints (5)
?>
这篇关于Wordpress,PHP,URL编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!