|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75153 wrap words are getting utf8 error
Submitted: 2017-09-04 14:35 UTC Modified: 2017-09-04 16:17 UTC
From: patrykmoura at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 7.0.23 OS: Unix and Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
20 + 26 = ?
Subscribe to this entry?

 [2017-09-04 14:35 UTC] patrykmoura at gmail dot com
When I do a wordwrap, or a preg_replace with a regex, or a implode with limit 10 with the word "Higienização", it returns "Higieniza??ão" instead of "Higienizaç ão". I guess there's something about the Ç word.


Test script:
echo wordwrap("Higienização", 10, " ", true);
echo implode(PHP_EOL, str_split("Higienização", 10));
echo preg_replace('/([^\s]{10})(?=[^\s])/', '$1'.' ', $string);

Expected result:
"Higienizaç ão"

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-04 15:57 UTC]
-Status: Open +Status: Not a bug
 [2017-09-04 15:57 UTC]
As with many string functions wordwrap() is not multibyte safe. Unfortunately the mbstring extension does not have an equivalent, but the user comments in the docs for wordwrap suggest a couple PCRE-based solutions for UTF-8 encoding.
 [2017-09-04 16:13 UTC] patrykmoura at gmail dot com

I understand the reason for wordwrap, but, why the other ways I've tried, lead me to the same error?
 [2017-09-04 16:17 UTC]
Both wordwrap() and str_split() are not multibyte-safe. Your PCRE version just misses the /u modifier.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Jun 03 05:03:39 2023 UTC