New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The options of IBM iconv does not work and outputs the NOTICE logs #791

Closed
ushiday opened this Issue Nov 30, 2018 · 4 comments

Comments

2 participants
@ushiday
Copy link

ushiday commented Nov 30, 2018

This is:

What is the expected behavior?

For example, if you decide whether the iconv options works.

 //\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Shared\StringHelper.php

    //----- New property -----//
    /**
     * Is iconv // IGNORE // TRANSLIT dose work?
     *
     * @var bool
     */
    private static $isIconvOptionsEnabled;

    //----- New method -----//
    /**
     * Get whether iconv options is available.
     *
     * @return bool
     */
    public static function getIsIconvOptionsEnabled()
    {
        if (isset(self::$isIconvOptionsEnabled)) {
            return self::$isIconvOptionsEnabled;
        }

        if (!self::getIsIconvEnabled()) {
            self::$isIconvOptionsEnabled = false;

            return false;
        }
        
        // Not IBM AIX (IBMi)
        if (! defined('PHP_OS') || ! @stristr(PHP_OS, 'AIX') ){
            self::$isIconvOptionsEnabled = true;

            return true;
        }

        // CUSTOM: IBM iconv  "//IGNORE//TRANSLIT" dose not work
        if (!@iconv('UTF-8', 'UTF-16LE//IGNORE//TRANSLIT', 'x')) {
            self::$isIconvOptionsEnabled = false;

            return false;
        }

        self::$isIconvOptionsEnabled = true;

        return true;

    }

    //----- Change method -----//
    public static function convertEncoding($value, $to, $from)
    {
        if (self::getIsIconvEnabled()) {
            if (self::getIsIconvOptionsEnabled()) {
                $result = iconv($from, $to . '//IGNORE//TRANSLIT', $value);
            }else{
                $result = iconv($from, $to , $value);
            }
            if (false !== $result) {
                return $result;
            }
        }

        return mb_convert_encoding($value, $to, $from);
    }

What is the current behavior?

My system (IBM i) dose not work "// IGNORE // TRANSLIT" options on iconv.
Then, it outputs the NOTICE log.

What are the steps to reproduce?

The reason is that the iconv's options is always specified in the following code.


    public static function convertEncoding($value, $to, $from)
    {
        if (self::getIsIconvEnabled()) {
            $result = iconv($from, $to . '//IGNORE//TRANSLIT', $value);
            if (false !== $result) {
                return $result;
            }
        }

        return mb_convert_encoding($value, $to, $from);
    }

Enviroments

PHP version: 7.1
PhpSpreadsheet version: 1.4.1
@PowerKiKi

This comment has been minimized.

Copy link
Member

PowerKiKi commented Dec 15, 2018

Can you confirm that //IGNORE works //TRANSLIT does not work ?

@ushiday

This comment has been minimized.

Copy link

ushiday commented Dec 19, 2018

Can you confirm that //IGNORE works //TRANSLIT does not work ?

Thanks, PowerKiKi.
"// IGNORE", does it work on AIX ?
In IBM i's PASE (AIX runtime environment) it may not work.
Since I have separated "IGNORE" and "// TRANSLIT", I have checked it yet.
At least, both did not work.
When PHPExcel was used, the NOTICE log was not output because there is no iconv option.

@ushiday

This comment has been minimized.

Copy link

ushiday commented Dec 19, 2018

Can you confirm that //IGNORE works //TRANSLIT does not work ?

Hi PowerKiKi.
I checked "// IGNORE" and "// TRANSLIT" .
Both options did not work.
It may occur because of IBMi's PHP.
Thanks.

Check program iconv-test.php

<?php
if (extension_loaded('iconv')) {
    echo 'loaded iconv'. '<br>' ;
}else{
    echo 'unload iconv'. '<br>' ;
}
//both
iconv('UTF-8', 'UTF-16LE//IGNORE//TRANSLIT', 'x');
//igcore only
iconv('UTF-8', 'UTF-16LE//IGNORE', 'x');
//translit only
iconv('UTF-8', 'UTF-16LE//TRANSLIT', 'x');
exit(0);

Browser output

loaded iconv

Notice: iconv(): Wrong charset, conversion from `UTF-8' to `UTF-16LE//IGNORE//TRANSLIT' is not allowed in /www/zendcore/htdocs/phptest/ushida/iconv-test.php on line 10

Notice: iconv(): Wrong charset, conversion from `UTF-8' to `UTF-16LE//IGNORE' is not allowed in /www/zendcore/htdocs/phptest/ushida/iconv-test.php on line 13

Notice: iconv(): Wrong charset, conversion from `UTF-8' to `UTF-16LE//TRANSLIT' is not allowed in /www/zendcore/htdocs/phptest/ushida/iconv-test.php on line 16

@PowerKiKi PowerKiKi closed this in 3b0c686 Jan 2, 2019

@ushiday

This comment has been minimized.

Copy link

ushiday commented Jan 7, 2019

Hi PowerKiKi.
Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment