|
18 | 18 | * @package php-utf-8 |
19 | 19 | * @subpackage functions |
20 | 20 | */ |
| 21 | +/* Function from https://github.com/nicolas-grekas/Patchwork-UTF8 */ |
21 | 22 | function wordwrap ($str, $width = 75, $break = "\n", $cut = FALSE) |
22 | 23 | { |
23 | | - $width = (int)$width; |
| 24 | + $width = (int)$width; |
24 | 25 | $str = explode($break, $str); |
25 | 26 |
|
26 | | - $iLen = count($str); |
27 | | - $result = array(); |
28 | | - $line = ''; |
29 | | - $lineLen = 0; |
| 27 | + $i_len = count($str); |
| 28 | + $result = array(); |
| 29 | + $line = ''; |
| 30 | + $line_len = 0; |
30 | 31 |
|
31 | | - for ($i = 0; $i < $iLen; ++$i) |
| 32 | + for ($i = 0; $i < $i_len; ++$i) |
32 | 33 | { |
33 | | - $words = explode(' ', $str[$i]); |
| 34 | + $words = explode(' ', $str[$i]); |
34 | 35 | $line && $result[] = $line; |
35 | | - $lineLen = len($line); |
36 | | - $jLen = count($words); |
| 36 | + $line_len = len($line); |
| 37 | + $jLen = count($words); |
37 | 38 |
|
38 | 39 | for ($j = 0; $j < $jLen; ++$j) |
39 | 40 | { |
40 | 41 | $w = $words[$j]; |
41 | 42 | $wLen = len($w); |
42 | 43 |
|
43 | | - if ($lineLen + $wLen < $width) |
| 44 | + if ($line_len + $wLen < $width) |
44 | 45 | { |
45 | 46 | if ($j) |
| 47 | + { |
46 | 48 | $line .= ' '; |
47 | | - $line .= $w; |
48 | | - $lineLen += $wLen + 1; |
| 49 | + } |
| 50 | + $line .= $w; |
| 51 | + $line_len += $wLen + 1; |
49 | 52 | } |
50 | 53 | else |
51 | 54 | { |
52 | 55 | if ($j || $i) |
| 56 | + { |
53 | 57 | $result[] = $line; |
54 | | - $line = ''; |
55 | | - $lineLen = 0; |
| 58 | + } |
| 59 | + $line = ''; |
| 60 | + $line_len = 0; |
56 | 61 |
|
57 | 62 | if ($cut && $wLen > $width) |
58 | 63 | { |
59 | 64 | $w = split($w); |
60 | 65 |
|
61 | 66 | do |
62 | 67 | { |
63 | | - $result[] = implode('', array_slice($w, 0, $width)); |
64 | | - $line = implode('', $w = array_slice($w, $width)); |
65 | | - $lineLen = $wLen -= $width; |
| 68 | + $result[] = implode('', array_slice($w, 0, $width)); |
| 69 | + $line = implode('', $w = array_slice($w, $width)); |
| 70 | + $line_len = $wLen -= $width; |
66 | 71 | } |
67 | 72 | while ($wLen > $width); |
68 | 73 | $w = implode('', $w); |
69 | 74 | } |
70 | | - |
71 | | - $line = $w; |
72 | | - $lineLen = $wLen; |
| 75 | + $line = $w; |
| 76 | + $line_len = $wLen; |
73 | 77 | } |
74 | 78 | } |
75 | 79 | } |
|
0 commit comments