简体   繁体   English

使用perl和html的链接中的空格

[英]Spaces in links using perl and html

I have a problem with spaces using perl. 我有使用perl的空格问题。 I'm taking my informations from a db and I'm using them for a query string, but if there is a space, I can't validate my page. 我从数据库获取信息,并将其用于查询字符串,但是如果有空间,则无法验证我的页面。

<a href="fish.cgi?fish=White Shark">White Shark</a>

Is there something I can do? 有什么我可以做的吗?

Turn your URLs into URI objects which will take care of all escaping and normalization for you. 将您的URL转换为URI对象,这将为您处理所有转义和规范化。 They can also be used as strings. 它们也可以用作字符串。

use URI;

# Prints fish.cgi?fish=White%20Shark
print URI->new("fish.cgi?fish=White Shark");

I'd recommend this over individually escaping URIs. 我推荐这个,而不是单独转义的URI。 Once you have a URI object, you know it's safe to use. 一旦有了URI对象,就知道可以安全使用。

You can replace the spaces in links with %20 which is the URL-encoded version for a space. 您可以将链接中的空格替换为%20 ,后者是空格的URL编码版本。 You may have to strip this out again after it's been posted, not quite sure. 你可能不得不在发布后再次将其剥离,不太确定。

Example: www.google.ca/this site would be encoded as www.google.ca/this%20site 例如: www.google.ca/this site将被编码为www.google.ca/this%20site

So your version would be fish.cgi?fish=White%20Shark , this should post properly. 因此,您的版本将是fish.cgi?fish=White%20Shark ,这应该正确发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM