note 60785 added to function.wordwrap

From: Date: Mon, 16 Jan 2006 16:37:17 +0000
Subject: note 60785 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-101930@lists.php.net to get a copy of this message
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 ); ?> ---- Submitter IP: 64.246.30.37 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60785 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60785&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60785&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60785&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60785&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60785&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60785&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60785&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60785&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101930) next »