0

I try to convert an internationalized Domain Name (IDN) into its punycode equivalent using the idn function from OS (Ubuntu). Here is my simple script :

<?php
$dom = "名がドメイン.net";
echo $dom."\n";
exec("idn $dom", $out, $var);
print_r($out);
echo "\n";
echo "result :$var\n";
?>

This code is not working into my browser, $out is an empty array and $var = 1 (guess there is an error). But when I run the code with php-cli, everything is fine and the result as it should be :

名がドメイン.net
Array
(
    [0] => xn--v8jxj3d1dzdz08w.net
)

result :0

Do you have some clue of what is happening ?

awar33
  • 11
  • 1
  • You probably enabled the [php5-idn module](http://php.net/manual/en/ref.intl.idn.php) in order to use this function? Keep in mind that the Apache PHP and the command line PHP both have their own configuration. Did you enable the module in both configuration files? – Nic Wortel Jul 03 '14 at 11:03
  • Since you're using `exec`, it finds the `idn` command via your `$PATH` setting. If the command isn't in one of the standard system binary directories, the webserver won't find it. Try using the full path to the command. – Barmar Jul 03 '14 at 11:06
  • No I have not enabled the php5-idn module. The idn function I used is from the system (command line in Ubuntu), this is why I used the php exec function. – awar33 Jul 03 '14 at 11:06
  • I have tried calling full path (/usr/bin/idn) but it didn't worked. It's not a $PATH problem, because if I try the script with a non-IDN domain, it works on both (php and php-cli) – awar33 Jul 03 '14 at 12:32

0 Answers0