Code Monkey home page Code Monkey logo

php-idna2's Introduction

php-idna2

PHP IDNA extension

PHP extension for dealing with internationalized domain names, providing both IDNA 2003 and IDNA 2008 processing functions.

Description

Dealing with Internationalized Domain Names (IDN) basically means to encode Non-ASCII domain labels into ASCII-compatible encoding (prefixed with "xn--") and vice versa. For example, the domain name name www.böthin.de is encoded to www.xn--bthin-jua.de by way of the well known Punycode algorithm. However, the question of how to consider arbitrary Unicode strings as domain labels in general is more complex and has to do with normalization processes and Unicode character classifications.

This extension makes the functionallity of two C-librarys available:

  • GNU Libidn (IDNA 2003) and
  • Idnkit-2 from the JPRS registry (IDNA 2008).

There is an online IDN tool based on this extension.

Note:

This is an experimantal tool suitable for dealing with advanced IDNA tasks. For more simple tasks, there are other solutions for handling IDN in PHP, for example PHP's intl framework.

Sample usage

    // 㯙㯜㯙㯟 is the Punycode decoded string of "domain"
    $utf8 = idna2_to_utf8(array(0x3BD9,0x3BDC,0x3BD9,0x3BDF));
    assert($utf8 === "\xe3\xaf\x99\xe3\xaf\x9c\xe3\xaf\x99\xe3\xaf\x9f");
    $codepoints = idna2_from_utf8($utf8); // array(0x3BD9,0x3BDC,0x3BD9,0x3BDF)
    
    $punycode = idna2_punycode_encode($utf8);
    assert($punycode === "domain"); 
    assert($utf8 === idna2_punycode_decode($punycode));
    
    $encoded = idna2_encode("㯙㯜㯙㯟.net");
    assert("xn--domain.net" === $encoded);

See the API documentation for an overview.

Prerequisites

Installation

Within the source directory, the following should work:

$ phpize
$ ./configure
$ make
$ make install

After successful installation you should have idna2.so within your php extension directory. In order to make this extension usable to your php code, add the following line to your php.ini:

extension=idna2.so

php-idna2's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.