PHP 8.5.0 Alpha 4 available for testing

Voting

: one minus one?
(Example: nine)

The Note You're Voting On

info at hsdn dot org
14 years ago
Wordwrap with UTF-8 supports, returns as array.

<?php

function mb_wordwrap_array($string, $width)
{
if ((
$len = mb_strlen($string, 'UTF-8')) <= $width)
{
return array(
$string);
}

$return = array();
$last_space = FALSE;
$i = 0;

do
{
if (
mb_substr($string, $i, 1, 'UTF-8') == ' ')
{
$last_space = $i;
}

if (
$i > $width)
{
$last_space = ($last_space == 0) ? $width : $last_space;

$return[] = trim(mb_substr($string, 0, $last_space, 'UTF-8'));
$string = mb_substr($string, $last_space, $len, 'UTF-8');
$len = mb_strlen($string, 'UTF-8');
$i = 0;
}

$i++;
}
while (
$i < $len);

$return[] = trim($string);

return
$return;
}

?>

<< Back to user notes page

To Top