Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts

    Problem with url greek characters in IE

    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.

    Code:
    $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.

    Code:
    <?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?

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,248
    Thanks
    12
    Thanked 340 Times in 336 Posts
    PHP also has a set of URL functions (urlencode(), rawurlencode(), http_build_query())
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    ktsixit (03-01-2010)

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts
    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:

    Code:
    <?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?

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,248
    Thanks
    12
    Thanked 340 Times in 336 Posts
    don’t use htmlentities() in the query string, "&" is a reserved character.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    ktsixit (03-01-2010)

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts
    You mean something like this?

    Code:
    ........
    <?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.
    Last edited by ktsixit; 03-01-2010 at 11:12 AM.

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,248
    Thanks
    12
    Thanked 340 Times in 336 Posts
    I think, I like this line better …
    PHP Code:
    $queryString_met "&" http_build_query($newParams); 
    EDIT: and I’d read the URL by parse_url(), gives you an array right away
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts
    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=Διάφορα

  • #8
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,248
    Thanks
    12
    Thanked 340 Times in 336 Posts
    Quote Originally Posted by php.net/urlencode
    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 …
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #9
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts
    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.

    Code:
    $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.
    Last edited by ktsixit; 03-01-2010 at 12:50 PM.

  • #10
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,248
    Thanks
    12
    Thanked 340 Times in 336 Posts
    Quote Originally Posted by ktsixit View Post
    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
    PHP Code:
    unset($params['pageNum_met']);
    $params['totalRows_met'] = $totalRows_met 
    instead of shifting elements to a new array?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •