note 19808 deleted from function.substr by aidan
| From: | aidan@php.net | Date: | Sat, 03 Jul 2004 07:56:07 +0000 |
| Subject: | note 19808 deleted from function.substr by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72390@lists.php.net to get a copy of this message | ||
Note Submitter: php@say.no.to.spam.thezed.net
----
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 :)