Mega Code Archive

 
Categories / Php / Strings
 

Discarding empty elements with preg_split()

<? $text=<<<TEXT "asdf.asdf,asdf!asdf TEXT; $words = preg_split('/[",.!\s]/', $text, -1, PREG_SPLIT_NO_EMPTY); print 'There are ' . count($words) .' words in the text.'; ?>