Monday, September 29, 2014

Check paragraph is in upper case or lower case

There is some situation when you need to check a whole paragraph is in upper case or lower case in php coding.

Below is simple function which will help you to solve your problem:

*****************************************************************************

function checkCase($paragraph){
    if(isset($paragraph) && $paragraph!=""):
        $paragraph=preg_replace('/[^A-Za-z0-9\-]/'," ", $paragraph);
        $paraArr=array_filter(explode(" ",$paragraph));
        $totalword=count($paraArr);
        $capsCount=0;
        foreach($paraArr as $word):
            if(ctype_upper($word)):
                $capsCount++;          
            endif;
        endforeach;
            if($capsCount == $totalword):
            return true;
            else:
            return false;
            endif;
        return $capsCount;
    endif;
}



**************************FUNCTON CALLING **********************************

$testcase = "THIS IS PHPSOLLUTIONS.BLOGSPOT.IN TESTING PARAGRAPH TO CHECK THAT PARAGRAPH IS IN UPPER CASE OR LOWER CASE";

if(checkCase($testcase)){
echo "Paragraph is in Upper case.";
}else{
echo "Paragraph is in Lower case.";
}




Happy coding guys.
Chears  :)


Related Posts Plugin for WordPress, Blogger...