PHP's wordwrap()
function doesn't work correctly for multi-byte strings like UTF-8.
There are a few examples of mb safe functions in the comments, but with some different test data they all seem to have some problems.
The function should take the exact same parameters as wordwrap()
.
Specifically be sure it works to:
- cut mid-word if
$cut = true
, don't cut mid-word otherwise - not insert extra spaces in words if
$break = ' '
- also work for
$break = "\n"
- work for ASCII, and all valid UTF-8
Here's my own attempt at a function that passed a few of my own tests, though I can't promise it's 100% perfect, so please post a better one if you see a problem.
Here is the multibyte wordwrap function i have coded taking inspiration from of others found on the internet.
Dont' forget to configure PHP for using UTF-8 with :
I hope this will help. Guillaume