友好网址中西里尔字符的问题
事情是这样的。我有像这样的友好网址
http://site.com/blog/read/мъдростта-на-вековете
最后一段实际上是友好的标题博客文章。问题是当我尝试将该段传递到数据库时,西里尔字体变成类似 %D1%8A%D0%B4%D1%80%D0%BE%D1%81%D1%8мъдростта-на-вековете),但如果我选择“复制网址位置”,最后一段又会变成这些奇怪的字符。我正在使用 CodeIgniter 并且所有内容都设置为 UTF-8。
请帮忙! :(
Here's the thing. I have friendly urls like
http://site.com/blog/read/мъдростта-на-вековете
The last segment is actually the friendly title of the blog article. The problem is when I try to pass that segment to the database, the cyrillic fonts turn into something like %D1%8A%D0%B4%D1%80%D0%BE%D1%81%D1%8 and couldn't match the database record. In the address bar in my browser it looks normal (мъдростта-на-вековете) but if I choose 'copy url location' the last segment again turns into these strange characters. I'm using CodeIgniter and everything is set to UTF-8.
Please help! :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
文本只是被编码以符合 URL 规范。
将数据回显到日志中,以查看您实际尝试传递到数据库的内容。
您应该能够使用 urldecode 对其进行解码。
The text is just being encoded to fit the specification for URLs.
Echo out the data to a log to see what you are actually trying to pass to the database.
You should be able to decode it with urldecode.
上面的答案是可以的,但是如果您想使用带有西里尔字母的路由,这是不够的。例如,如果您有 http://site.com/блог/статия/мъдростта-на-вековете 您将不得不这样做像这样的东西:
在
config/routes.php
中:$route['блог/статия/(:any)'] = "blog/article/$1";
在 < code>system/core/URI.php ,在
function _explode_segments()
中,可以改为这样,
加上控制器和函数就解决了上面的问题。
The above answers are ok, but if you want to use routing with cyrillic it isn't enough. For example if you have http://site.com/блог/статия/мъдростта-на-вековете you will have to do something like this:
In
config/routes.php
:$route['блог/статия/(:any)'] = "blog/article/$1";
In
system/core/URI.php
, in thefunction _explode_segments()
, you can changeto
This will solve the above problem plus controllers and functions.
实际上,Firefox 在这里欺骗了您:URL 实际上是经过 url 编码的,但显示得好像没有经过编码。因此,在服务器上复制粘贴并检索它将会对 URL 进行编码。
(不确定其他浏览器是否有同样的行为。)
Actually, Firefox is cheating you here: the URL actually is url-encoded, but is shown as if it wasn't. So copy-pasting and retrieving it on the server will have the URL encoded.
(Not sure if other browsers behave in the same way.)