note 60785 deleted from function.wordwrap by danbrown

From: Date: Sun, 17 May 2009 18:32:15 +0000
Subject: note 60785 deleted from function.wordwrap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155133@lists.php.net to get a copy of this message
Note Submitter: lean[--]roico[at]gm[--]ail[dot]com ---- To @Anthony Catel Wouldn't be easier, more correct and more simple to cut the words having more characters than the $limit parameter like the following code? <? function cut_words( $txt , $limit, $html_nl = 0 ) { $str_nl = $html_nl == 1 ? "<br>" : ( $html_nl == 2 ? "<br />" : "\n" ); $pseudo_words = explode( ' ',$txt ); $txt = ''; foreach( $pseudo_words as $v ) { if( ( $tmp_len = strlen( $v ) ) > $limit ) { $final_nl = is_int( $tmp_len / $limit ); $txt .= chunk_split( $v, $limit, $str_nl ); if( !$final_nl ) $txt = substr( $txt, 0, - strlen( $str_nl ) ); $txt .= ' '; } else $txt .= $v . ' '; } return substr( $txt, 0 , -1 ); } ?> For using it this is a sample: <? function cut_words( 'big words text here' , 15, 2 ); ?>

« previous php.notes (#155133) next »