note 93963 deleted from function.substr by googleguy

From: Date: Tue, 22 Oct 2013 11:17:24 +0000
Subject: note 93963 deleted from function.substr by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197078@lists.php.net to get a copy of this message
Note Submitter: info /a/ nopticon /dot/ com ---- <?php // Substring without losing word meaning and // tiny words (length 3 by default) are included on the result. // "..." is added if result do not reach original string length function _substr($str, $length, $minword = 3) { $sub = ''; $len = 0; foreach (explode(' ', $str) as $word) { $part = (($sub != '') ? ' ' : '') . $word; $sub .= $part; $len += strlen($part); if (strlen($word) > $minword && strlen($sub) >= $length) { break; } } return $sub . (($len < strlen($str)) ? '...' : ''); } ?>

« previous php.notes (#197078) next »