note 94368 added to function.wordwrap

From: Date: Fri, 30 Oct 2009 18:06:14 +0000
Subject: note 94368 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-162293@lists.php.net to get a copy of this message
After I got some problems with my function to convert a BB-text into HTML. Long words didn't really fit into the layout and only wordwarp() also added breaks to words which would fit into the layout or destroy the other HTML-tags.... So this is my solution. Only words with strlen() >= 40 are edited with wordwarp(). <?php function bb2html($bb) { $words= explode(' ', $bb); // string to array foreach ($words as $word) { $break = 0; for ($i = 0; $i < strlen($word); $i++) { if ($break >= 40) { $word= wordwrap($word, 40, '-<br>', true); //add <br> every 40 chars $break = 0; } $break++; } $newText[] = $word; //add word to array } $bb = implode(' ', $newText); //array to string return $bb; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 217.232.126.215 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/94368 Del: integrated -- https://master.php.net/note/delete/94368/integrated Del: useless -- https://master.php.net/note/delete/94368/useless Del: bad code -- https://master.php.net/note/delete/94368/bad+code Del: spam -- https://master.php.net/note/delete/94368/spam Del: non-english -- https://master.php.net/note/delete/94368/non-english Del: in docs -- https://master.php.net/note/delete/94368/in+docs Del: other reasons-- https://master.php.net/note/delete/94368 Reject -- https://master.php.net/note/reject/94368 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162293) next »