Last active
August 29, 2015 14:11
-
-
Save kjantzer/3da1d9ce55a658ee4389 to your computer and use it in GitHub Desktop.
SmartSplit - requires underscore.js
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
| function smart_split($str){ | |
| $vals = array(); | |
| if( preg_match("/,/", $str) ) // comma delimited | |
| $vals = explode(',', $str); | |
| else if( preg_match("/\t/", $str) ) | |
| $vals = explode("\t", $str); | |
| else | |
| $vals = explode("\n", $str); | |
| foreach($vals as &$val){ $val = trim($val); } | |
| return $vals; | |
| } |
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
| smartSplit = function(str){ | |
| var vals = []; | |
| if( str.match(/,/) ) // comma separated | |
| vals = str.split(',') | |
| else if( str.match(/\t/) ) // tab separated | |
| vals = str.split("\t") | |
| else | |
| vals = str.split("\n") // new line separated | |
| return _.invoke(vals, 'trim') // trim whitespace | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment