Skip to content

(php 8.2) Function utf8_encode() is deprecated in PHPOffice/PhpWord/Shared/Text.php on line 139 #2370

Closed
@Bricobit

Description

@Bricobit

Deprecated: Function utf8_encode() is deprecated in .../PHPOffice/PhpWord/Shared/Text.php on line 139

The original code is this

/**
      * Return UTF8 encoded value
      *
      * @param string $value
      * @return string
      */
     public static function toUTF8($value = '') {
         if (!is_null($value) && !self::isUTF8($value)) {
             $value = utf8_encode($value);
         }

         return $value;
     }

and the code that I have used to solve it is the following

  /**
      * Return UTF8 encoded value
      *
      * @param string $value
      * @return string
      */
     public static function toUTF8($value = ''){
         if (!is_null($value) && !self::isUTF8($value)) {
             $currentEncoding = mb_detect_encoding($value);
             if($currentEncoding){
                 $value = mb_convert_encoding($value, 'UTF-8', $currentEncoding);
             }
         }

         return $value;
     }

The error disappears but when generating the word it breaks and does not open, appears blank.
Any solution?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions