编码 url 不编码

发布于 2024-09-16 14:05:19 字数 360 浏览 7 评论 0原文

我正在 Moveable Type 中的模板中工作,并希望执行以下操作:

<a href="http://twitter.com/share?url=<$mt:EntryPermalink encode_url="1" $>">Twitter</a>

一切正常,但我担心当前链接或在某些时候即使我使用标题 mt 标签,它可能不适合浏览器地址栏。我认为您可以使用encode_url =“1”,但它似乎没有对我的标题或链接进行编码。例如:我的标题中包含空格,而生成的代码中仍然包含空格。另外对于上面的例子,http:// 不应该以特殊的方式编码吗?因为它不这样做。

我在这里做错了什么吗?

I am working in a template in Moveable Type and would like to do the following:

<a href="http://twitter.com/share?url=<$mt:EntryPermalink encode_url="1" 
gt;">Twitter</a>

It all works but I'm worried that the current link or at some point even if I use a title mt tag that it might not be right for the browser address bar. I thought you could use encode_url="1" but it doesn't appear to encode my titles or links. For example: I have a title with spaces in it and the resulting code still has the spaces in it. Also for the example above shouldn't the http:// be encoded in a special way? Because it doesn't do it.

Am I doing something wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑叹一世浮沉 2024-09-23 14:05:19

我刚刚检查了此代码,它对我来说正常输出。我正在使用MT 4.34。我在索引模板中使用了以下模板代码:

<mt:Var name="url" value="http://google.com/hello I have spaces">
<mt:Entries lastn="1">
    Permalink: <mt:EntryPermalink encode_url="1"><br />
    Fake URL: <mt:Var name="url" encode_url="1">
</mt:Entries>

我得到了以下输出:

Permalink: http%3A%2F%2Fwww.capndesign.com%2Farchives%2F2010%2F09%2Fthe_big_picture_scenes_from_china.php
Fake URL: http%3A%2F%2Fgoogle.com%2Fhello%20I%20have%20spaces

所以我确认您正在使用支持此修饰符的当前版本的 MT(4.34 或 5.x),因为空格和特殊字符绝对应该被HTML实体所取代。我还会尝试上面提供的代码,以查看您是否获得相同的输出(除非您的永久链接显然会不同)。

I just checked this code and it is outputting properly for me. I am using MT 4.34. I used the following template code in an index templated:

<mt:Var name="url" value="http://google.com/hello I have spaces">
<mt:Entries lastn="1">
    Permalink: <mt:EntryPermalink encode_url="1"><br />
    Fake URL: <mt:Var name="url" encode_url="1">
</mt:Entries>

And I got the following output:

Permalink: http%3A%2F%2Fwww.capndesign.com%2Farchives%2F2010%2F09%2Fthe_big_picture_scenes_from_china.php
Fake URL: http%3A%2F%2Fgoogle.com%2Fhello%20I%20have%20spaces

So I would confirm that you're using a current version of MT (4.34 or 5.x) that supports this modifier, because the spaces and special characters should definitely be getting replaced with HTML entities. I'd also try the code I provided above to see if you get the same output (except your permalink will obviously be different).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文