Git Product home page Git Product logo

php-punycode's Introduction

Punycode

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

A Bootstring encoding of Unicode for Internationalized Domain Names in Applications (IDNA).

Install

composer require true/punycode:~2.0

Usage

<?php

// Import Punycode
use TrueBV\Punycode;

$Punycode = new Punycode();
var_dump($Punycode->encode('renangonçalves.com'));
// outputs: xn--renangonalves-pgb.com

var_dump($Punycode->decode('xn--renangonalves-pgb.com'));
// outputs: renangonçalves.com

FAQ

1. What is this library for?

This library converts a Unicode encoded domain name to a IDNA ASCII form and vice-versa.

2. Why should I use this instead of PHP's IDN Functions?

If you can compile the needed dependencies (intl, libidn) there is not much difference. But if you want to write portable code between hosts (including Windows and Mac OS), or can't install PECL extensions, this is the right library for you.

php-punycode's People

Contributors

abcdmitry avatar ceeram avatar fahad19 avatar grahamcampbell avatar mlocati avatar renan avatar skroczek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-punycode's Issues

IDNA2008 support?

If I'm not wrong, this (great) library supports the IDNA2003 specs.
What about adding support to IDNA2008 too?

Twig extension?

What about including in this repository a Twig extension for methods encode and decode?
I'm currently thinking to a couple of filters punycode_encode and punycode_decode.
Of course I can send a PR if it's interesting.

when i'm run i got this output : string(10) "tester.com"

can u explain about the error when i'm run this source i got string(10) "tester.com"
this my php version :
PHP 7.1.16 (cli) (built: Mar 28 2018 21:27:36) ( ZTS MSVC14 (Visual C++ 2015) x86 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

Thank you.

Test failing with PHP 7.3

From Fedora QA
https://apps.fedoraproject.org/koschei/package/php-true-punycode?collection=f30

There was 1 failure:
1) TrueBV\PunycodeTest::testEncodeUppercase with data set #19 ('άέήίΰαβγδεζηθικλμνξοπρσστυφχ.com', 'xn--hxacdefghijklmnopqrstuvw0...2a.com')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'xn--hxacdefghijklmnopqrstuvw0caz0a1a2a.com'
+'xn--lsan50ceafgqijklmnopqrstuvwx2ca0afw3a4a.com'
/builddir/build/BUILD/php-punycode-a4d0c11a36dd7f4e7cd7096076cab6d3378a071e/tests/PunycodeTest.php:46
FAILURES!

punycode encoding does not always match up with idn_to_ascii

Hi first of thanks for making this library.

I think i found a bug:
Tried to convert : άέήίΰαβγδεζηθικλμνξοπρςστυφχ.com
Got this result from $punycode->encode($domain):
xn--hxacdefghijklmnopqrstuvwxyz0a1a2a.com

idn_to_ascii returns this result:
xn--hxacdefghijklmnopqrstuvw0caz0a1a2a.com

The backend domain registry provider we use indicates the encoded with this library as invalid punycode and the second(idn_to_ascii) as valid.

UTF-8 encoding problem

All mb_* string functions should make use of last parameter, which is encoding. Without this (at least in my case) it did not encode polish diacritical symbols encoded in utf-8 (i.e. 'gwóźdź.pl'). My suggested solution, that worked in my case, is to create private $encoding = 'utf-8' class attribute and use it in all 6 mb_something occurs along with encoding setter, just in case anyone needs different encoding. Cheers!

Abandon in favor of symfony/polyfill-intl-idn?

Follow up of #28: the symfony/polyfill-intl-idn package now implements the idn_to_ascii and idn_to_utf8 functions.

Since this repo is not maintained anymore, maybe it should be declared as abandoned here and on packagist?

PHP 8.1 deprecation warnings

PHP 8.1 throws the following deprecation warnings:

PHP Deprecated: Implicit conversion from float 0.7836734693877551 to int loses precision in /vendor/true/punycode/src/Punycode.php on line 151
PHP Deprecated: Implicit conversion from float 27.428571428571427 to int loses precision in /vendor/true/punycode/src/Punycode.php on line 145

Undefined index notice

2019-01-23T08:25:03+00:00 NOTICE (5): Undefined index: in /var/www/html/vendor/true/punycode/src/Punycode.php on line 228

I get a few thousand of these a day, no idea what the input is that causes it though unfortunately since it's only a notice not a throwable so I can't catch it and log the input $url with the message.

Encoding/decoding Guangdong TLD

As reported by mail:


Hello,

I have found a bug in your code https://github.com/true/php-punycode .

It can sucessfully decode xn--p1ai , but it cannot correctly decode the TLD xn--xhq521b . Did I do something wrong?

mb_internal_encoding('utf-8');
include __DIR . '/punycode.inc.php';
$punycoder = new True\Punycode();
$x = $punycoder->decode('xn--p1ai');
var_dump($x);
$x = $punycoder->decode('xn--xhq521b');
var_dump($x);

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.