Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php get long word in array

function longestWord($txt) {
    $words = preg_split('#[^a-z0-9áéíóúñç]#i', $txt, -1, PREG_SPLIT_NO_EMPTY);
    usort($words, function($a, $b) { return strlen($b) - strlen($a); });
    return $words[0];
}
echo longestWord("Where did the big Elephant go?");
// prints Elephant
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #long #word #array
ADD COMMENT
Topic
Name
1+6 =