Skip to content

Commit a836c32

Browse files
authored
Merge pull request #2472 from PHPOffice/pr2447
Remove deprecated utf8_encode in PHP 8.2
2 parents d1e7ed7 + 9dfe0b0 commit a836c32

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

docs/changes/1.x/1.2.0.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434
- Moved documention from ReadTheDocs to MkDocs & Github Pages by [@Progi1984](https://github.com/Progi1984) in GH-2465
3535
- Bump phpstan/phpstan-phpunit from 1.3.13 to 1.3.14 by [@dependabot](https://github.com/dependabot) in [#2457](https://github.com/PHPOffice/PHPWord/pull/2457)
3636
- Bump symfony/process from 5.4.26 to 5.4.28 by [@dependabot](https://github.com/dependabot) in [#2456](https://github.com/PHPOffice/PHPWord/pull/2456)
37-
- Bump phpunit/phpunit from 9.6.10 to 9.6.11 by [@dependabot](https://github.com/dependabot) in [#2455](https://github.com/PHPOffice/PHPWord/pull/2455)
37+
- Bump phpunit/phpunit from 9.6.10 to 9.6.11 by [@dependabot](https://github.com/dependabot) in [#2455](https://github.com/PHPOffice/PHPWord/pull/2455)
38+
- Remove deprecated utf8_encode in PHP 8.2 by [@mhcwebdesign](https://github.com/mhcwebdesign) in [#2447](https://github.com/PHPOffice/PHPWord/pull/2447) & [#2472](https://github.com/PHPOffice/PHPWord/pull/2472)

src/PhpWord/Shared/Text.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ public static function isUTF8($value = '')
145145
public static function toUTF8($value = '')
146146
{
147147
if (null !== $value && !self::isUTF8($value)) {
148-
$value = utf8_encode($value);
148+
if (PHP_VERSION_ID < 80200) {
149+
$value = utf8_encode($value);
150+
} else {
151+
$value = mb_convert_encoding($value, 'UTF-8', mb_list_encodings());
152+
}
149153
}
150154

151155
return $value;

src/PhpWord/TemplateProcessor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ protected static function ensureMacroCompleted($macro)
257257
protected static function ensureUtf8Encoded($subject)
258258
{
259259
if (!Text::isUTF8($subject) && null !== $subject) {
260-
$subject = utf8_encode($subject);
260+
if (PHP_VERSION_ID < 80200) {
261+
$subject = utf8_encode($subject);
262+
} else {
263+
$subject = mb_convert_encoding($subject, 'UTF-8', mb_list_encodings());
264+
}
261265
}
262266

263267
return (null !== $subject) ? $subject : '';

0 commit comments

Comments
 (0)