How to get the length of the last word in a string with PHP

1 Answer

0 votes
$str = "c++ c php javascript rust";

$words = explode(" ", $str);

echo "The length of the last word is: " . strlen($words[count($words) - 1]);
 
 
 
/*
run:
 
The length of the last word is: 4

*/

 



answered May 4, 2024 by avibootz
...