SUMMARY Function Description Reference Link str_split(STRING, CHARACTERS) Split the characters of the given string into an array.Ĭlick Here explode(DELIMITER, STRING) Split the given string into an array, separated by the given DELIMITER.Ĭlick Here preg_split(EXPRESSION, STRING) Split the given string into an array by the given regular expression.Ĭlick Here str_word_count(STRING, FORMAT, LIST) Kind of a multi-purpose tool. That’s all for this guide, and here is a small section on some extras and links that may be useful to you. Finally, the last LIST parameter is optional – We can use this one to override and tell PHP to accept this list of characters as “valid English word”.But the index of the array will correspond to the starting position of the word in the string. 1 will return an array of valid words in the string – Yes, this is useful if you want to filter out all the gibberish in a string.0 will simply count the total number of valid English words in the string.The second parameter is the important one that “changes” the MODE of the function.The first parameter is the STRING itself.Kind of confusing, but str_word_count(STRING, MODE, LIST) takes in 3 parameters.* 39 - Word count? Yes, the str_word_count() may not seem like a function that is used to convert a string to an array, but it is… At least for 2 out of 3 of its possible “modes”. $thearray = str_word_count($thestring, 2, 0 - Foo, (C) 3RD PARAMETER - CHARACTERS TO CONSIDER AS "ENGLISH WORD" $thearray = str_word_count($thestring, 2)
(B3) FORMAT 2 - RETURN ARRAY OF VALID WORDS, WITH STARTING POSTION Print_r($thearray) // Foo, Bar, hello, world, Goodbye, world, John, Doe $thearray = str_word_count($thestring, 1) (B2) FORMAT 1 - RETURN ARRAY OF VALID WORDS (B1) FORMAT 0 - RETURNS NUMBER OF VALID WORDS Goodbye world3 = (B) STR_WORD_COUNT(STRING, FORMAT, LIST)