note 98123 deleted from function.wordwrap by peehaa
| From: | peehaa@php.net | Date: | Thu, 09 Mar 2017 09:10:07 +0000 |
| Subject: | note 98123 deleted from function.wordwrap by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208875@lists.php.net to get a copy of this message | ||
Note Submitter: kouber at php dot net
----
If you need a function to cut only words longer than N characters, feel free to use the function
below:
<?php
function wrap($str, $width=75, $break="\n") {
return preg_replace('#(\S{'.$width.',})#e', "chunk_split('$1',
".$width.", '".$break."')", $str);
}
echo wrap('aaaa bbb cc dddd-dddd', 3, ' ');
?>
The above example will output: "aaa a bbb cc ddd d-d ddd "