Coder Social home page Coder Social logo

Comments (3)

dharple avatar dharple commented on September 26, 2024

Pleased to present for your consideration:

# cat test.php
<?php

require_once 'vendor/autoload.php';

printf("%s %s\n", ICONV_IMPL, ICONV_VERSION);

$str = 'Sláinte';

for ($i = 0; $i < mb_strlen($str); $i++) {
    printf("%s -> %s\n",
        mb_substr($str, $i, 1),
        iconv('UTF-8', 'ASCII//TRANSLIT', mb_substr($str, $i, 1))
    );
}
# php7.4 -f test.php
glibc 2.31
S -> S
l -> l
á -> a
i -> i
n -> n
t -> t
e -> e
# php8.0 -f test.php
glibc 2.31
S -> S
l -> l
á -> ?
i -> i
n -> n
t -> t
e -> e
# LANG=en_US.UTF-8 php8.0 -f test.php
glibc 2.31
S -> S
l -> l
á -> ?
i -> i
n -> n
t -> t
e -> e

However:

# cat test-force-utf8.php
<?php

require_once 'vendor/autoload.php';

printf("%s %s\n", ICONV_IMPL, ICONV_VERSION);

setlocale(LC_ALL, 'en_US.UTF-8');

$str = 'Sláinte';

for ($i = 0; $i < mb_strlen($str); $i++) {
    printf("%s -> %s\n",
        mb_substr($str, $i, 1),
        iconv('UTF-8', 'ASCII//TRANSLIT', mb_substr($str, $i, 1))
    );
}
# php8.0 -f test-force-utf8.php
glibc 2.31
S -> S
l -> l
á -> a
i -> i
n -> n
t -> t
e -> e

from detox-php.

dharple avatar dharple commented on September 26, 2024

Essentially - the behavior of iconv is unpredictable.

from detox-php.

dharple avatar dharple commented on September 26, 2024

My solution:

# cat test-behat.php
<?php

require_once 'vendor/autoload.php';

use Behat\Transliterator\Transliterator;

$str = 'Sláinte';

for ($i = 0; $i < mb_strlen($str); $i++) {
    printf("%s -> %s vs %s\n",
        mb_substr($str, $i, 1),
        iconv('UTF-8', 'ASCII//TRANSLIT', mb_substr($str, $i, 1)),
        Transliterator::utf8toAscii(mb_substr($str, $i, 1)),
    );
}
# php7.4  -f test-behat.php
S -> S vs S
l -> l vs l
á -> a vs a
i -> i vs i
n -> n vs n
t -> t vs t
e -> e vs e
# php8.0 -f test-behat.php
S -> S vs S
l -> l vs l
á -> ? vs a
i -> i vs i
n -> n vs n
t -> t vs t
e -> e vs e

from detox-php.

Related Issues (3)

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.