note 19808 added to function.substr

From: Date: Tue, 12 Mar 2002 01:41:33 +0000
Subject: note 19808 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-27640@lists.php.net to get a copy of this message
A quick (and possibly nasty) way of getting the effect of a substr to break at a space (or punctuation) is to use ereg_replace: $length = 50; $mySubstring = ereg_replace("^(.{1,$length})[ .,].*", "\\1", $myOrigString); this will give you a string that is 50 characters at the most but won't break in the middle of a word. CheerZ :) -- http://www.php.net/manual/en/function.substr.php http://master.php.net/manage/user-notes.php?action=edit+19808 http://master.php.net/manage/user-notes.php?action=delete+19808 http://master.php.net/manage/user-notes.php?action=reject+19808

« previous php.notes (#27640) next »