note 92577 added to function.wordwrap

From: Date: Thu, 30 Jul 2009 05:16:44 +0000
Subject: note 92577 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-158899@lists.php.net to get a copy of this message
I tried using mb functions to word wrap 10 long strings (200 unicode utf8 chars) and I hit execution timeout error. After searching and testing, I came up with this simple and fast function for unicode word wrap. //function to break up strings without whitespace chars in between //if $cut is true then strings will be forcefully break up even there are whitespace in between. function unicode_wordwrap($str, $len=50, $break=" ", $cut=false){ if(empty($str)) return ""; $pattern=""; if(!$cut) $pattern="/(\S{".$len."})/u"; else $pattern="/(.{".$len."})/u"; return preg_replace($pattern, "\${1}".$break, $str); } ---- Server IP: 64.71.164.2 Probable Submitter: 113.10.92.12 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/92577 Del: integrated -- https://master.php.net/note/delete/92577/integrated Del: useless -- https://master.php.net/note/delete/92577/useless Del: bad code -- https://master.php.net/note/delete/92577/bad+code Del: spam -- https://master.php.net/note/delete/92577/spam Del: non-english -- https://master.php.net/note/delete/92577/non-english Del: in docs -- https://master.php.net/note/delete/92577/in+docs Del: other reasons-- https://master.php.net/note/delete/92577 Reject -- https://master.php.net/note/reject/92577 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158899) next »