Commit c8b08211 authored by mso's avatar mso

Version 0.5.0 - 2007-04-14

git-svn-id: svn+ssh://85.214.81.201/srv/svn/repos/idna_convert/trunk@3154 35e3bc58-21ef-11dd-9788-dfbd14258a26
parent af28ec45
......@@ -2,9 +2,10 @@
* *
* IDNA Convert (idna_convert.class.php) *
* *
* http://idnaconv.phlymail.de mailto:team@phlymail.de *
* http://idnaconv.phlymail.de mailto:phlymail@phlylabs.de *
*******************************************************************************
* (c) 2004-2005 phlyLabs, Berlin *
* (c) 2004-2007 phlyLabs, Berlin *
* This file is encoded in UTF-8 *
*******************************************************************************
Introduction
......@@ -20,34 +21,36 @@ what you would expect them to do. You are allowed to use complete domain names,
simple strings and complete email addresses as well. That means, that you might
use any of the following notations:
- www.nörgler.com
- www.nörgler.com
- xn--nrgler-wxa
- xn--brse-5qa.xn--knrz-1ra.info
Errors, incorrectly encoded or invalid strings will lead to either a FALSE
response (when in strict mode) or to only partially converted strings.
You can query the occured error by calling the method get_last_error() when
using the PHP4 version or through exceptions when the PHP5 version is used.
You can query the occured error by calling the method get_last_error().
Unicode strings are expected to be either UTF-8 strings, UCS-4 strings or UCS-4
arrays. The default format is UTF-8. For setting different encodings, you can
call the method setParams() - please see the inline documentation for details.
ACE strings (the Punycode form) are always 7bit ASCII strings.
ATTENTION: We no longer supply the PHP5 version of the class. It is not
necessary for achieving a successfull conversion, since the supplied PHP code is
compatible with both PHP4 and PHP5. We expect to see no compatibility issues
with the upcoming PHP6, too.
Files
-----
idna_convert.class.php - The actual class
idna_convert.class.php5.php - A PHP5 version, contributed by Marcus Nix
idna_convert.create.npdata.php - Useful for (re)creating the NPData file
npdata.ser - Serialized data for NamePrep
example.php - An example web page for converting
ReadMe.txt - This file
LICENCE - The LGPL licence file
For using the class, you will have to either use idna_convert.class.php or
idna_convert.class.php5.php from your application.
The class is contained in idna_convert.class.php.
MAKE SURE to copy the npdata.ser file into the same folder as the class file
itself!
......@@ -55,23 +58,19 @@ itself!
Examples
--------
1. Say we wish to encode the domain name nörgler.com:
1. Say we wish to encode the domain name nörgler.com:
// Include the class
include_once('idna_convert.class.php');
// Instantiate it *
$IDN = new idna_convert();
// The input string, if input is not UTF-8 or UCS-4, it must be converted before
$input = utf8_encode('nörgler.com');
$input = utf8_encode('nörgler.com');
// Encode it to its punycode presentation
$output = $IDN->encode($input);
// Output, what we got now
echo $output; // This will read: xn--nrgler-wxa.com
* If you wish to use the PHP5 version of the class, be aware, that the constructor
is named Net_IDNA_php5() since this file is used in the PEAR version of this class.
Likeweise, you can also instantiate the PHP4 version with new Net_IDNA_php4().
2. We received an email from a punycoded domain and are willing to learn, how
the domain name reads originally
......@@ -79,14 +78,14 @@ echo $output; // This will read: xn--nrgler-wxa.com
// Include the class
include_once('idna_convert.class.php');
// Instantiate it (depending on the version you are using) with
$IDN = new Net_IDNA_php4();
$IDN = new idna_convert();
// The input string
$input = 'andre@xn--brse-5qa.xn--knrz-1ra.info';
// Encode it to its punycode presentation
$output = $IDN->decode($input);
// Output, what we got now, if output should be in a format different to UTF-8
// or UCS-4, you will have to convert it before outputting it
echo utf8_decode($output); // This will read: andre@börse.knürz.info
echo utf8_decode($output); // This will read: andre@börse.knörz.info
3. The input is read from a UCS-4 coded file and encoded line by line. By
......@@ -96,7 +95,7 @@ echo utf8_decode($output); // This will read: andre@b
// Include the class
include_once('idna_convert.class.php');
// Instantiate it
$IDN = new Net_IDNA_php4();
$IDN = new dinca_convert();
// Iterate through the input file line by line
foreach (file('ucs4-domains.txt') as $line) {
echo $IDN->encode(trim($line), 'ucs4_string');
......@@ -119,5 +118,6 @@ Contact us
In case of errors, bugs, questions, wishes, please don't hesitate to contact us
under the email address above.
The team of
phlymail.de
\ No newline at end of file
The team of phlyLabs
http://phlylabs.de
mailto:phlymail@phlylabs.de
\ No newline at end of file
<?php
$encoded = '';
$decoded = '';
$add = '';
header('Content-Type: text/html; charset=UTF-8');
if (isset($_REQUEST['pear'])) {
include('idna_convert.class.php5.php');
$add = '<input type="hidden" name="pear" value="'.$_REQUEST['pear'].'" />'."\n";
$IDN = new Net_IDNA_php5();
} else {
include('idna_convert.class.php');
$add = '';
$IDN = new idna_convert();
}
require_once('idna_convert.class.php');
$IDN = new idna_convert();
if (isset($_REQUEST['encode'])) {
$decoded = isset($_REQUEST['decoded']) ? stripslashes($_REQUEST['decoded']) : '';
$encoded = $IDN->encode($decoded);
......@@ -19,70 +15,68 @@ if (isset($_REQUEST['decode'])) {
}
if (isset($_REQUEST['lang'])) {
if ('de' == $_REQUEST['lang'] || 'en' == $_REQUEST['lang']) $lang = $_REQUEST['lang'];
$add.= '<input type="hidden" name="lang" value="'.$_REQUEST['lang'].'" />'."\n";
$add .= '<input type="hidden" name="lang" value="'.$_REQUEST['lang'].'" />'."\n";
} else {
$lang = 'en';
}
if (!isset($encoded)) $encoded = '';
if (!isset($decoded)) $decoded = '';
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<!DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Punycode Converter</title>
<title>phlyLabs Punycode Converter</title>
<meta name="author" content="phlyLabs">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
body {
color: rgb(0, 0, 0);
background-color: rgb(255, 255, 255);
font-size: 10pt;
font-family: Verdana, Helvetica, Sans-Serif;
color:black;
background:white;
font-size:10pt;
font-family:Verdana, Helvetica, Sans-Serif;
}
body, form {
margin: 0px;
margin:0px;
}
form {
display: inline;
display:inline;
}
input {
font-size: 8pt;
font-family: Verdana, Helvetica, Sans-Serif;
font-size:8pt;
font-family:Verdana, Helvetica, Sans-Serif;
}
#mitte {
text-align: center;
vertical-align: middle;
text-align:center;
vertical-align:middle;
}
#round {
background-color: rgb(230, 230, 240);
border: 1px solid black;
text-align: center;
vertical-align: middle;
padding: 10px;
background-color:rgb(230, 230, 240);
border:1px solid black;
text-align:center;
vertical-align:middle;
padding:10px;
}
.thead {
font-size: 9pt;
font-weight: bold;
font-size:9pt;
font-weight:bold;
}
#copy {
font-size: 8pt;
color: rgb(60, 60, 80);
font-size:8pt;
color:rgb(60, 60, 80);
}
#subhead {
font-size: 8pt;
font-size:8pt;
}
#bla {
font-size: 8pt;
text-align: left;
font-size:8pt;
text-align:left;
}
</style>
</head>
......@@ -91,7 +85,7 @@ input {
<tr>
<td id="mitte">
<div id="round">
<strong>Net_IDNA (PHP IDNA Converter)</strong><br />
<strong>phlyLabs` pure PHP IDNA Converter</strong><br />
<span id="subhead">
See <a href="http://faqs.org/rfcs/rfc3490.html" title="IDNA" target="_blank">RFC3490</a>,
<a href="http://faqs.org/rfcs/rfc3491.html" title="Nameprep, a Stringprep profile" target="_blank">RFC3491</a>,
......@@ -143,20 +137,20 @@ input {
</tr>
<tr>
<td align="right">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" name="decoded" value="<?php echo htmlentities($decoded, null, 'UTF-8'); ?>" size="48" maxlength="255" /><br />
<input type="submit" name="encode" value="Encode &gt;&gt;" /><?php echo $add; ?>
</form>
</td>
<td align="left">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" name="encoded" value="<?php echo htmlentities($encoded, null, 'UTF-8'); ?>" size="48" maxlength="255" /><br />
<input type="submit" name="decode" value="&lt;&lt; Decode" /><?php echo $add; ?>
</form>
</td>
</tr>
</table><br />
<span id="copy">Version used: 0.4.4; (c) <a href="http://phlylabs.de">phlyLabs</a> 2004-2006</span>
<span id="copy">Version used: 0.5.0; (c) <a href="http://phlylabs.de">phlyLabs</a> 2004-2007</span>
</div>
</td>
</tr>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment