Created
July 5, 2018 04:37
-
-
Save LiamKarlMitchell/00427e70d7feb107e61a5e1423e4c467 to your computer and use it in GitHub Desktop.
PHP Misc functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Splits a string on commas, trims whitespace and ignores empty items. | |
| // Does not split an item with internal spaces like "some thing". | |
| function splitter($input) { | |
| return preg_split ('/\s*,\s*/', $input, -1, PREG_SPLIT_NO_EMPTY); | |
| } | |
| $labels = splitter("Oh bob, Sagget, , ,,,, ,, asdas d, a,1,2,3,4,5,"); | |
| foreach($labels as $label) { | |
| echo "• $label\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment