note 64045 added to function.wordwrap

From: Date: Thu, 06 Apr 2006 10:51:37 +0000
Subject: note 64045 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-107434@lists.php.net to get a copy of this message
Hope this helps if u want to cut long words in a text, having html or smthing in it. <?php function cutLongWords($str, $len = false) { if ($len == false && isset($GLOBALS['cutLongWordLenght'])) $len = $GLOBALS['cutLongWordLenght']; else $GLOBALS['cutLongWordLenght'] = $len = ($len != 24) ? $len : 24; if (is_array($str)) return $str[1].' '.cutLongWords($str[2], $len); return preg_replace_callback( "#([\w\d-]{".$len."})([\w\d-]*?)(?!(-|\d|\w|\/|\.))#iUs", 'cutLongWords', $str); } // testing $text = 'put your looooooooooooooo0000000000000ooo0000oong text here'; $new = cutLongWords($text); print('<pre>'); print($text."<br />"); print($new); print('</pre>'); $new2 = cutLongWords($text, 12); print('<pre>'); print($text."<br />"); print($new2); print('</pre>'); ?> This is some solution using and explaining preg_replace callbacks. Dunno if it's buggy... Not testet... ---- Server IP: 217.160.72.57 Probable Submitter: 212.112.208.131 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- http://master.php.net/note/edit/64045 Del: integrated -- http://master.php.net/note/delete/64045/integrated Del: useless -- http://master.php.net/note/delete/64045/useless Del: bad code -- http://master.php.net/note/delete/64045/bad+code Del: spam -- http://master.php.net/note/delete/64045/spam Del: non-english -- http://master.php.net/note/delete/64045/non-english Del: in docs -- http://master.php.net/note/delete/64045/in+docs Del: other reasons-- http://master.php.net/note/delete/64045 Reject -- http://master.php.net/note/reject/64045 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107434) next »