![]() |
Here is simple Exampple to get Longest Word from a Sentence in PHP. |
<?php
$string = "Where did the big Elephant go?";
$words = explode(' ', $string);
$longestWordLength = 0;
$longestWord = '';
foreach ($words as $word) { if (strlen($word) > $longestWordLength) { $longestWordLength = strlen($word); $longestWord = $word; }
}
echo $longestWord;
// Outputs: "Elephant"
?>
Category
: |
Web Tutorial |
Sub Category
: |
PHP String Tutorial |
Uploaded by
: |
Admin |
Read Article https://horje.com/learn/1434/reference