note 98696 added to function.wordwrap

From: Date: Thu, 01 Jul 2010 12:31:07 +0000
Subject: note 98696 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-170617@lists.php.net to get a copy of this message
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) ; ---- Server IP: 69.147.83.197 Probable Submitter: 95.18.181.79 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/98696 Del: integrated -- https://master.php.net/note/delete/98696/integrated Del: useless -- https://master.php.net/note/delete/98696/useless Del: bad code -- https://master.php.net/note/delete/98696/bad+code Del: spam -- https://master.php.net/note/delete/98696/spam Del: non-english -- https://master.php.net/note/delete/98696/non-english Del: in docs -- https://master.php.net/note/delete/98696/in+docs Del: other reasons-- https://master.php.net/note/delete/98696 Reject -- https://master.php.net/note/reject/98696 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170617) next »