note 83585 added to function.substr

From: Date: Tue, 03 Jun 2008 10:13:18 +0000
Subject: note 83585 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-140080@lists.php.net to get a copy of this message
easy and quick way to limit length of a text by not cutting full words: textLimit('some words', 7) is 'some...' function textLimit($string, $length, $replacer = '...') { if(strlen($string) > $length) return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer; return $string; } ---- Server IP: 195.54.192.44 Probable Submitter: 127.0.0.1 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/83585 Del: integrated -- https://master.php.net/note/delete/83585/integrated Del: useless -- https://master.php.net/note/delete/83585/useless Del: bad code -- https://master.php.net/note/delete/83585/bad+code Del: spam -- https://master.php.net/note/delete/83585/spam Del: non-english -- https://master.php.net/note/delete/83585/non-english Del: in docs -- https://master.php.net/note/delete/83585/in+docs Del: other reasons-- https://master.php.net/note/delete/83585 Reject -- https://master.php.net/note/reject/83585 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140080) next »