note 98696 deleted from function.wordwrap by danbrown
| From: | danbrown@php.net | Date: | Thu, 01 Jul 2010 13:05:44 +0000 |
| Subject: | note 98696 deleted from function.wordwrap by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170625@lists.php.net to get a copy of this message | ||
Note Submitter: vituko at gmail dot com
----
Sorry, I did'nt tested my last function against real UTF-8 (I wanted to see if the behavior was
the same when working with original function), so it was wrong.
It only looks for spaces, very ease to add new separators : tabs...
New version :
function mb_wordwrap ($cadea, $lonx=75, $sep="\n", $cortar_palabra=false) {
if (!$cortar_palabra)
return preg_replace
('#(([\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){1,'.$lonx.'}) (?!$)#',
'\1'.$sep, $cadea) ;
else
return preg_replace
('#(?:((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){1,'.$lonx.'})
|((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$lonx.'}))(?!$)#', '\1\2'.$sep,
$cadea) ;
}
$cadea = "áñäç áá á á á óà ûóasdf sdf a a aa a a a a a a
aa a a a a a a a a a asdfghjkl
áááááááááááááááááááááááá
asdfassdf af af asdfsdfsdf ad dfdfasdf fdfdasdf asdff ááááááááá
áááááááááá ááááááááááá" ;
echo mb_wordwrap ($cadea, 10, '#@#<br/>', 0) ;
echo '<br/><br/>' ;
echo wordwrap ($cadea, 10, '#@#<br/>', 0) ;
echo '<br/><br/>' ;
echo mb_wordwrap ($cadea, 10, '#@#<br/>', 1) ;
echo '<br/><br/>' ;
echo wordwrap ($cadea, 10, '#@#<br/>', 1) ;