note 99828 added to function.wordwrap
| From: | venimus at gmail dot com | Date: | Thu, 09 Sep 2010 09:21:11 +0000 |
| Subject: | note 99828 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172398@lists.php.net to get a copy of this message | ||
To cut long texts up to certain length without breaking words you can use this simple function
<?php
function cutstr($str, $length, $ellipsis=''){
$cut=(array)explode('\n\n',wordwrap($str),$length,'\n\n'));
return $cut[0].((strlen($cut)<strlen($str))?$ellipsis:'');
}
?>
Third parameter is added to the output string if it was cut, usually you should use '...'
----
Server IP: 69.147.83.197
Probable Submitter: 93.155.250.18
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/99828
Del: integrated -- https://master.php.net/note/delete/99828/integrated
Del: useless -- https://master.php.net/note/delete/99828/useless
Del: bad code -- https://master.php.net/note/delete/99828/bad+code
Del: spam -- https://master.php.net/note/delete/99828/spam
Del: non-english -- https://master.php.net/note/delete/99828/non-english
Del: in docs -- https://master.php.net/note/delete/99828/in+docs
Del: other reasons-- https://master.php.net/note/delete/99828
Reject -- https://master.php.net/note/reject/99828
Search -- https://master.php.net/manage/user-notes.php