note 62022 added to function.substr

From: Date: Fri, 17 Feb 2006 13:01:18 +0000
Subject: note 62022 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-103920@lists.php.net to get a copy of this message
/** * Cut string to n symbols and add delim but do not break words. * * Example: * <code> * $string = 'this is some content to be shortened'; * echo myfragment($string, 15); * </code> * * Output: 'this is some content...' * * @access public * @param string string we are operating with * @param integer character count to cut to * @param string|NULL delimiter. Default: '...' * @return string processed string **/ function myfragment($str, $n, $delim='...') { // {{{ $len = strlen($str); if ($len > $n) { preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches); return rtrim($matches[1]) . $delim; } else { return $str; } } // }}} ---- Server IP: 193.219.81.76 Probable Submitter: 213.197.149.226 (proxied: 192.168.0.3) ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62022 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62022&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62022&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62022&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62022&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62022&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62022&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62022&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62022&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103920) next »