PHP – Find uppercase/capitalized word in a string

The funcion, using preg_mat_all

function getCapWords($string)
 preg_match_all('/\b[A-Z][a-zA-Z]*\b/', $string, $matches);
 return $matches[0];

Now the test and action!

$words = getCapWords(@string);
$words = array_unique(@$words); 

foreach ($words as $palavra)
 if ( $palavra == strtoupper($palavra)
 { echo 'uppercased word'; }



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.