...

View Full Version : Problem with url greek characters in IE



ktsixit
03-01-2010, 11:01 AM
Hi all,
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 tried to use the javascript "encodeURI" function, with no results unfortunately.


<?php $aaa = sprintf("%s?pageNum_met=%d%s", $currentPage, max(0, $pageNum_met - 1), $queryString_met); ?>
<script type="text/javascript">
var whatever = "<?= $aaa ?>";
var whatever1 = encodeURI(whatever);
document.getElementById('previous_type').href = whatever1;
</script>

Any suggestions please?

Dormilich
03-01-2010, 11:39 AM
PHP also has a set of URL functions (urlencode(), rawurlencode(), http_build_query())

ktsixit
03-01-2010, 11:58 AM
hello Dormilich and thank you for your reply. I have also tried using the urlencode() function but the returned url is not valid. I may have done some kind of mistake, I just don't know why it's not working:


<?php
$aaa = sprintf("%s?pageNum_met=%d%s", $currentPage, max(0, $pageNum_met - 1), $queryString_met);;

$bbb = urlencode($aaa);
?>

<a href="<?php echo $bbb; ?>">&nbsp;<<&nbsp;</a>

Any suggestions on this one?

Dormilich
03-01-2010, 12:01 PM
don’t use htmlentities() in the query string, "&" is a reserved character.

ktsixit
03-01-2010, 12:06 PM
You mean something like this?


........
<?php $queryString_met = "&" . implode("&", $newParams); ?>
........
.......
<?php
$aaa = sprintf("%s?pageNum_met=%d%s", $currentPage, max(0, $pageNum_met - 1), $queryString_met);;

$bbb = urlencode($aaa);
?>

<a href="<?php echo $bbb; ?>">&nbsp;<<&nbsp;</a>

i tested it and it's not returning a valid url too.

Dormilich
03-01-2010, 12:11 PM
I think, I like this line better …

$queryString_met = "&" . http_build_query($newParams);
EDIT: and I’d read the URL by parse_url(), gives you an array right away

ktsixit
03-01-2010, 12:23 PM
I still don't get valid urls with this one.
By the way my database and page encoding are utf-8.

The url I get is:
%2Fused.php%3FpageNum_met%3D0%26totalRows_met%3D18%260%3Dtype%253D%2525CE%252594%2525CE%2525B9%2525C E%2525AC%2525CF%252586%2525CE%2525BF%2525CF%252581%2525CE%2525B1

The one with the greek characters would be:
used.php?pageNum_met=0&totalRows_met=18&type=Διάφορα

Dormilich
03-01-2010, 12:36 PM
This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.

you have to use urlencode() in the right way …

ktsixit
03-01-2010, 01:26 PM
I'm not a php expert, I'm trying to understand exactly what's the problem here but I don't think I actually do.

Anyway, I tested the following code both in firefox and Internet explorer and checked the output results.


$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 = "&" . http_build_query($newParams);
}
}
echo "<div style=\"color:#fff\">".$queryString_met."</div>";
echo "<div style=\"color:#fff\">".urlencode($queryString_met)."</div>";
$queryString_met = sprintf("&totalRows_met=%d%s", $totalRows_met, $queryString_met);

In firefox the output "&type=%CE%94%CE%B9%CE%AC%CF%86%CE%BF%CF%81%CE%B1" works fine. In internet explorer it's not.

Also, in IE, every time I go to the next page, the new $queryString_met seems to add itself to the previous one. I'm really confused here, I'm sorry.

Dormilich
03-01-2010, 01:55 PM
In firefox the output "&type=%CE%94%CE%B9%CE%AC%CF%86%CE%BF%CF%81%CE%B1" works fine. In internet explorer it's not.

then you have a problem with IE, not with PHP.

wouldn’t it be simpler to do

unset($params['pageNum_met']);
$params['totalRows_met'] = $totalRows_met
instead of shifting elements to a new array?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum