Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LiamKarlMitchell/00427e70d7feb107e61a5e1423e4c467 to your computer and use it in GitHub Desktop.
Save LiamKarlMitchell/00427e70d7feb107e61a5e1423e4c467 to your computer and use it in GitHub Desktop.
PHP Misc functions
<?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