Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-08-2013, 07:56 AM   PM User | #1
fail
Regular Coder

 
Join Date: Dec 2009
Location: Hong Kong
Posts: 118
Thanks: 8
Thanked 0 Times in 0 Posts
fail is an unknown quantity at this point
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..
fail is offline   Reply With Quote
Old 01-08-2013, 10:45 AM   PM User | #2
Thyrosis
New Coder

 
Join Date: Nov 2012
Posts: 89
Thanks: 4
Thanked 12 Times in 12 Posts
Thyrosis is on a distinguished road
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.
Thyrosis is offline   Reply With Quote
Old 01-10-2013, 03:34 AM   PM User | #3
fail
Regular Coder

 
Join Date: Dec 2009
Location: Hong Kong
Posts: 118
Thanks: 8
Thanked 0 Times in 0 Posts
fail is an unknown quantity at this point
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.
fail is offline   Reply With Quote
Old 01-10-2013, 06:01 AM   PM User | #4
fail
Regular Coder

 
Join Date: Dec 2009
Location: Hong Kong
Posts: 118
Thanks: 8
Thanked 0 Times in 0 Posts
fail is an unknown quantity at this point
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..
fail is offline   Reply With Quote
Old 01-12-2013, 09:00 AM   PM User | #5
fail
Regular Coder

 
Join Date: Dec 2009
Location: Hong Kong
Posts: 118
Thanks: 8
Thanked 0 Times in 0 Posts
fail is an unknown quantity at this point
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 is offline   Reply With Quote
Old 01-14-2013, 04:08 AM   PM User | #6
fail
Regular Coder

 
Join Date: Dec 2009
Location: Hong Kong
Posts: 118
Thanks: 8
Thanked 0 Times in 0 Posts
fail is an unknown quantity at this point
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..
fail is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:31 AM.


Advertisement
Log in to turn off these ads.