note 74097 deleted from function.preg-split by tularis
| From: | tularis@php.net | Date: | Thu, 03 May 2007 22:24:11 +0000 |
| Subject: | note 74097 deleted from function.preg-split by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126170@lists.php.net to get a copy of this message | ||
Note Submitter: honza FCKSPAM odvarko DOT cz
----
If you want to convert a full-value string into shorthand, keeping only some specific characters,
you may find this useful. Take a note of how the separator works (useful for SEO URLs etc.)
<?php
function shorthand($str, $separator='-') {
$chunks = preg_split('/[^a-zA-Z0-9]+/', $str, -1, PREG_SPLIT_NO_EMPTY);
return implode($separator, $chunks);
};
$text = ' ..:: Yeah, cup of coffee! ::.. ';
// prints 'yeah-cup-of-coffee'
echo strtolower(shorthand($text));
?>