CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Punycode converter not working on ONE page - why? (http://www.codingforums.com/showthread.php?t=285445)

fail 01-08-2013 07:56 AM

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

Thyrosis 01-08-2013 10:45 AM

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.

fail 01-10-2013 03:34 AM

Quote:

Originally Posted by Thyrosis (Post 1304797)
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.

fail 01-10-2013 06:01 AM

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

fail 01-12-2013 09:00 AM

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.

fail 01-14-2013 04:08 AM

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"); 



All times are GMT +1. The time now is 12:19 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.