无法将中文字符发布到我的搜索表单中

发布于 2024-10-18 14:05:08 字数 2153 浏览 6 评论 0原文

我在将中文字符发布到搜索表单时遇到了一些麻烦。它在本地主机上运行良好,但在我的网站上运行不佳。

搜索输入是这样的:假发

本地主机上的结果网址: http:// search.taobao.com/search?commend=all&isnew=2&q=%BC%D9%B7%A2&source=search1

网站上生成的网址: StackOverflow实际上对其进行了编码,但编码结果有所不同,事情是在网站上而不是q=%BC%D9%B7%A2上,我在url本身中得到了q=假发。 http://search.taobao.com/search?commend=all&isnew=2&q=%E5%81%87%E5%8F%91&source=search1

可以看到它实际上插入了查询中包含汉字。我不知道为什么这在 lcoahost 和实时网站上的工作方式不同。字符编码是:

<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />

但是我也尝试了UTF-8,没有改变。

这是我的表单的 html。搜索查询转到第二个输入框。第一个用于翻译,效果很好。不确定这是怎么回事以及我是否必须对字符进行编码以及为什么它在本地主机上工作??? 提前致谢!

 <div class="search-box">
 <form id="search" name="search" action="http://search1.taobao.com/browse/search_auction.htm?at_topsearch=1" method="post" target="_blank">
 <div class="search-form">
 <span class="search-q">
 <input type="text" autocomplete="off" accesskey="s" name="q" id="q" value="Translate and Find" style="width: 160px; font-family: Arial;" size="20" />
 </span>
 <button id="DoSearch" type="submit" style="font-weight: bold; font-family:Arial; color: #333; width: 165px;">
 Taobao Search</button>
 </div>
 <input type="hidden" name="sort" value="" />
 <input type="hidden" name="at_topsearch" value="1" />
 <input type="hidden" name="f" value="D9_5_1" />
 <input type="hidden" name="promote" value="" />
 <input type="hidden" name="isnew" value="2" />
 <input type="hidden" name="atype" value="b" />
 <input type="hidden" name="commend" value="all" />
 <input type="hidden" name="search_type" value="auction" />
 <input type="hidden" name="user_action" value="initiative" />
 <input type="hidden" name="ssid" value="s1-e" />
 </form>
 </div>
</div>

I'm having a bit of trouble posting chinese characters to a search form. It works great on localhost but not on my website.

The search input is this: 假发

The resulting url on localhost:
http://search.taobao.com/search?commend=all&isnew=2&q=%BC%D9%B7%A2&source=search1

The resulting url on the website:
StackOverflow actually encode's it,the encode result is different though, thing is that on the website instead of q=%BC%D9%B7%A2 I get q=假发 in the url itself.
http://search.taobao.com/search?commend=all&isnew=2&q=%E5%81%87%E5%8F%91&source=search1

You can see that it actually inserts the chinese characters into the query. I have no idea why this works differently on lcoahost and on a live site. The character encoding is:

<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />

But I tried UTF-8 as well, no changes.

here's the html of my form. The search query goes to the second input box. THe first one's for transaltion, which works fine. Not sure what's the deal and whether I have to encode the characters or not and why does it work on localhost???
Thanks in advance!

 <div class="search-box">
 <form id="search" name="search" action="http://search1.taobao.com/browse/search_auction.htm?at_topsearch=1" method="post" target="_blank">
 <div class="search-form">
 <span class="search-q">
 <input type="text" autocomplete="off" accesskey="s" name="q" id="q" value="Translate and Find" style="width: 160px; font-family: Arial;" size="20" />
 </span>
 <button id="DoSearch" type="submit" style="font-weight: bold; font-family:Arial; color: #333; width: 165px;">
 Taobao Search</button>
 </div>
 <input type="hidden" name="sort" value="" />
 <input type="hidden" name="at_topsearch" value="1" />
 <input type="hidden" name="f" value="D9_5_1" />
 <input type="hidden" name="promote" value="" />
 <input type="hidden" name="isnew" value="2" />
 <input type="hidden" name="atype" value="b" />
 <input type="hidden" name="commend" value="all" />
 <input type="hidden" name="search_type" value="auction" />
 <input type="hidden" name="user_action" value="initiative" />
 <input type="hidden" name="ssid" value="s1-e" />
 </form>
 </div>
</div>

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

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

发布评论

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

评论(1

还给你自由 2024-10-25 14:05:08

accept-charset="GB18030" 添加到您的表单标记中。我的猜测是,您的本地服务器将编码留给表单(例如 XAMPP 就是这样做的),并且实时服务器强制对信息进行编码。

如果这不起作用,您可以使用 PHP 对提交的信息强制进行编码。或者,如果您有能力修改服务器设置,则可以更改编码......但 PHP 选项要简单一百万倍。

Add accept-charset="GB18030" to your form tag. My guess is that your local server leaves the encoding up to the form (XAMPP does this for example), and the live server forces an encoding on the information.

If that doesn't work and you can use PHP to force an encoding on the submitted information. Or if you have the ability to modify server settings you can change the encoding.... But the PHP option is a million times simpler.

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