IE中的希腊网址字符出现问题 [英] Problem with greek url characters in IE
问题描述
我在我的网站中使用以下脚本来创建分页下一个上一个"功能.这实际上是Dreamweaver的代码.该脚本使用url获取一些值,然后重新创建它. IE7和IE8中的结果网址包含不可读的字符,并且最后该页面无法正常工作.
I'm using the following script in my website in order to create pagination "next-previous" functionality. It's a actually a Dreamweaver's code. The script uses the url to get some values and then it re-creates it. The result url in IE7 and IE8 contains non-readable characters and at the end the page does not work properly.
$queryString_met = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_met") == false &&
stristr($param, "totalRows_met") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_met = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_met = sprintf("&totalRows_met=%d%s", $totalRows_met, $queryString_met);
........
<a href="<?php printf("%s?pageNum_met=%d%s", $currentPage, max(0, $pageNum_met - 1), $queryString_met); ?>"> << </a>
我不知道代码的哪一部分负责此问题.你能帮我吗?
I don't understand which part of the code is responsible for this issue. Can you please help me?
推荐答案
htmlentities(implode(&",$ newParams));
htmlentities(implode("&", $newParams));
htmlentities
通常会不必要地对字符串中的所有非ASCII字节进行编码,并且,如果您未指定charset
参数,则猜测您的字符串是在ISO-8859-1中,对于希腊语,它们肯定会获胜不是. (希望您对网站中的所有内容都使用UTF-8.)
htmlentities
encodes all non-ASCII bytes in your string, usually needlessly, and, if you don't specify a charset
argument, guessing your strings are in ISO-8859-1, which for Greek they definitely won't be. (Hopefully, you're using UTF-8 for everything in your site.)
使用htmlspecialchars
代替,它将保留非ASCII字符,仅对真正必须编码的内容进行编码.
Use htmlspecialchars
instead, which will leave the non-ASCII characters alone and only encode what really does have to be encoded.
但是,要使这成为一个问题,您必须直接在URL中使用非ASCII字符.这确实是不可靠的.别.未编码的非ASCII字符在URI中根本无效;它们必须经过%
编码(例如,使用urlencode
). IRI允许使用非ASCII字符,浏览器可以自动将UTF-8编码和%-encoding转换为URI,但IE不会(总是)这样做.
However, for this to be an issue at all, you would have to be using non-ASCII characters directly in your URL. This is really unreliable; don't. Unencoded non-ASCII characters are not valid in a URI at all; they must be %
-encoded (eg. using urlencode
). IRIs allow non-ASCII characters, which browsers can automatically UTF-8-encode and %-encode to turn them into URIs, but IE doesn't (always) do that.
[此外,对于包含目标名称的 值,不仅仅是以它们开头的值,处理查询字符串的脚本都会失败.]
[Also the script to process query string will fail for any value containing the targeted names, not just those beginning with them.]
这篇关于IE中的希腊网址字符出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!