note 54441 added to function.substr

From: Date: Mon, 04 Jul 2005 18:23:03 +0000
Subject: note 54441 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-91434@lists.php.net to get a copy of this message
This function shortens the string down to maximum lengt defined in $max_lengt. If the string is longer the function finds the last occurance of a space and adds three dots at the end to illustrate that it is more text. If the string is without spaces it stops at exacly max lengt, also adding three dots. If the string is shorter than max lengt it returns the string as it is. This is useful for previewing long strings. function str_stop($string, $max_length){ if (strlen($string) > $max_length){ $string = substr($string, 0, $max_length); $pos = strrpos($string, " "); if($pos === false) { return substr($string, 0, $max_length)."..."; } return substr($string, 0, $pos)."..."; }else{ return $string; } } ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54441 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54441&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54441&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54441&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54441&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54441&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54441&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54441&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91434) next »