Created
December 2, 2012 23:11
-
-
Save enigmaticape/4191521 to your computer and use it in GitHub Desktop.
The little tokeniser that could
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 | |
function tokeniseString( $string ) { | |
$regex = "/([[:space:]]+)|([[:punct:]])/"; | |
$opts = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY; | |
$toks = preg_split( $regex, $string, -1, $opts ); | |
return $toks; | |
} | |
$string = "[various words!] 2 + (thirty thirsty_badgers), '9^7' | 6 >=2 "; | |
var_dump( tokeniseString( $string ) ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment