PHP Solution to Check Whether the String Contains Uppercase Characters

By | March 20, 2009

Today I had to deal with a big file full of different strings. I had to check whether the string contains uppercase characters or not. I’ve written a simple script and I think it might be useful for you. Here it is:

<?

$ex=array_map(“trim”, file(“strings.txt”));

foreach ($ex as $rex)
{
for ($i=0; $i<strlen($rex); $i++)
{
if (ctype_upper($rex{$i}))
{
echo $rex.”rn”;
break;
}
}
}

?>

Simple, isn’t it? We’re getting the list of strings into array, then we’re checking each one by characters. If an uppercase character is found, we’re stopping the character loop and printing the string. You’re welcome to do anything you want with these strings, I just think you might need the idea how to check the file for different characters existence. This script covers the uppercase chars, but you’re welcome to deal with any of them.

This script could be done using regular expressions in a smarter way; it’s just a simple and quick solution based on dirty code… :)