Skip to content
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
2 of 3 tasks
ushiday opened this issue Nov 30, 2018 · 4 comments
Closed
2 of 3 tasks

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

ushiday opened this issue Nov 30, 2018 · 4 comments

Comments

@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
Copy link
Member

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

@ushiday
Copy link
Author

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
Copy link
Author

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

@ushiday
Copy link
Author

ushiday commented Jan 7, 2019

Hi PowerKiKi.
Thank you very much.

guillaume-ro-fr pushed a commit to guillaume-ro-fr/PhpSpreadsheet that referenced this issue Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants