note 93963 added to function.substr

From: Date: Thu, 08 Oct 2009 18:52:24 +0000
Subject: note 93963 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-161524@lists.php.net to get a copy of this message
<?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)) ? '...' : ''); } ?> ---- Server IP: 200.110.240.132 Probable Submitter: 200.49.167.170 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/93963 Del: integrated -- https://master.php.net/note/delete/93963/integrated Del: useless -- https://master.php.net/note/delete/93963/useless Del: bad code -- https://master.php.net/note/delete/93963/bad+code Del: spam -- https://master.php.net/note/delete/93963/spam Del: non-english -- https://master.php.net/note/delete/93963/non-english Del: in docs -- https://master.php.net/note/delete/93963/in+docs Del: other reasons-- https://master.php.net/note/delete/93963 Reject -- https://master.php.net/note/reject/93963 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161524) next »