8000 The options of IBM iconv does not work and outputs the NOTICE logs · Issue #791 · PHPOffice/PhpSpreadsheet · GitHub 8000
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
The options of IBM iconv does not work and outputs the NOTICE logs #791
Closed
@ushiday

Description

@ushiday

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0