PHP 阻止 htmlspecialchars 转换 URL 中的数字

发布于 2025-01-06 04:51:00 字数 323 浏览 0 评论 0原文

我有这个网址,我需要将其传递给浏览器并希望对其进行编码。但是,我的 url 字符串中的数字也会被转换,从而导致问题。

这是我的字符串。

"http://domain.com/?w=132&h=132&zc=1&q=90&a=c"

如果我使用 htmlspecialchars,它会将 132 转换为 100,这是错误的。如何预防呢?

更新:也许我应该提到我的字符串看起来像这样,因为我正在使用 timthumb 脚本。

另外我什至不确定我是否需要编码任何东西?或者我提供的网址安全吗?

I have this url which I need to pass to the browser and would like to encode it. However I have numbers in the url string which also gets converted and thus causes issues.

Here is my string.

"http://domain.com/?w=132&h=132&zc=1&q=90&a=c"

And if i use htmlspecialchars, it would convert both 132 to 100 which is wrong. How to prevent that?

UPDATE: perhaps I should mention that my string looks like that because I am using timthumb script.

Also I am not even sure if I need to encode anything? or is the URL i provided safe?

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

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

发布评论

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

评论(3

诗化ㄋ丶相逢 2025-01-13 04:51:00

如果我错了请原谅我,但是你不应该使用 urlencode 吗?

urlencode()
PHP.net 参考

Forgive me if I'm wrong, but shouldn't you use urlencode instead?

urlencode()?
PHP.net reference

芸娘子的小脾气 2025-01-13 04:51:00

htmlspecialchars 不会影响数字...我不知道你在做什么来得到它...

无论如何,只要通过 urlencode()

htmlspecialchars doesn't affect numbers... I have no idea what you're doing to get that...

Anyway, just pass it through urlencode()

可遇━不可求 2025-01-13 04:51:00

htmlspecialchars() 仅转换 5 个字符:

'&' (ampersand) becomes '&'
'"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
"'" (single quote) becomes ''' only when ENT_QUOTES is set.
'<' (less than) becomes '<'
'>' (greater than) becomes '>'

它不接触数字、字母、或其他符号。

htmlspecialchars() only converts 5 characters:

'&' (ampersand) becomes '&'
'"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
"'" (single quote) becomes ''' only when ENT_QUOTES is set.
'<' (less than) becomes '<'
'>' (greater than) becomes '>'

It doesn't touch numbers, letters, or other symbols.

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