note 74097 added to function.preg-split
| From: | honzaFCKSPAModvarkoDOTcz at osu1 dot php dot net | Date: | Sat, 24 Mar 2007 15:00:19 +0000 |
| Subject: | note 74097 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124772@lists.php.net to get a copy of this message | ||
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));
?>
----
Server IP: 212.24.129.110
Probable Submitter: 212.11.118.139
----
Manual Page -- http://www.php.net/manual/en/function.preg-split.php
Edit -- https://master.php.net/note/edit/74097
Del: integrated -- https://master.php.net/note/delete/74097/integrated
Del: useless -- https://master.php.net/note/delete/74097/useless
Del: bad code -- https://master.php.net/note/delete/74097/bad+code
Del: spam -- https://master.php.net/note/delete/74097/spam
Del: non-english -- https://master.php.net/note/delete/74097/non-english
Del: in docs -- https://master.php.net/note/delete/74097/in+docs
Del: other reasons-- https://master.php.net/note/delete/74097
Reject -- https://master.php.net/note/reject/74097
Search -- https://master.php.net/manage/user-notes.php