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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Punycode converter not working on ONE page - why?

    I have another strange problem. Since I work a lot with URLs


    PHP Code:
    include_once('idna_convert.class.php');
    $IDN = new idna_convert();
       
    $feeder = array("glühwein.dk","你好吗.com","madrid.com","zürich.eu","hallo.de");

    foreach( 
    $feeder as $key => $value )
    {

    echo 
    $value."<br>";
    $url $IDN->encode($value);

    echo 
    $url."<p>";

    }

    /*
    Output:
    glühwein.dk
    xn--glhwein-o2a.dk

    你好吗.com
    xn--6qqu8ipsf.com

    madrid.com
    madrid.com

    zürich.eu
    xn--zrich-kva.eu

    hallo.de
    hallo.de
    */ 
    The sample page outputs exactly as above. However, in my 'real' page it works perfectly only on not alphanumeric URLs (Chinese, Japanese) - but not on URLs with ü , ö etc. Could it be performance related?

    Any clue why that is?

    PS: I am on PHP 5.3.1
    Last edited by fail; 01-08-2013 at 08:42 AM.

  • #2
    Regular Coder
    Join Date
    Nov 2012
    Posts
    115
    Thanks
    7
    Thanked 12 Times in 12 Posts
    Simple: Domain zürich.eu (or xn--zrich-kva.eu) isn't available at all.

    Just enter those 4 in your browser. All of them work, apart from zürich.eu or xn--zrich-kva.eu.

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Thyrosis View Post
    Simple: Domain zürich.eu (or xn--zrich-kva.eu) isn't available at all.
    Punycode is simple converting a string with special characters into a domain format. It does not have to an existing URL.

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I am still totally puzzled. I put the code from the top into the page that gives me trouble - and the top parts works.

    Japanese works, Chinese works, ä ü ö do NOT work, but ő works, but ñ does not. It works when I string them up in an array and decode them in a FOREACH loop. I can add a variable with a value into the Array. But when I put the same url into a variable (not array!) and then into the test array it will not work.

    I got already a new idna_convert.class.php - same issue.


    PS: Same error with PHP 5.4.7
    Last edited by fail; 01-11-2013 at 01:37 PM.

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I still can't solve this problem. I presume it's related to the charcater encoding. All problem domain names are in ASCII format. Even though the original HTML source format is UTF-8.

    I presume the output from preg_match_all is in ASCII - now need to check either how to convert it back, or how to make preg_match_all output UTF-8.

    After it is ASCII the data is extremely resistant to changes and I didn't manage you to get it back to UTF-8. I don't understand why utf8_encode() or mb_convert_encoding() fail to work.

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Solved! This REALLY took me some time!

    I tried to work it via mySQL and noted that whatever I try, data gets input as i.e. solglasögon.net instead of solglasögon.net

    I then did a try and put this before the string:

    PHP Code:
    $value str_replace("&amp;#246;","ö",$value);  // except the amp; 
    and it worked according plan!

    Not to do a str_replace() for every special character I did:

    PHP Code:
    $value html_entity_decode($valueENT_COMPAT"UTF-8"); 
    Last edited by fail; 01-14-2013 at 04:19 AM.


  •  

    Posting Permissions

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