Jump to content

Recommended Posts

Thanks!

I had to make some minor changes to his function:
[code]    function get_upper_percent($str)
    {
        $len   = 0;
        $upper = 0;

        $strlen = strlen($str);

        for($i = 0; $i <= $strlen; ++$i)
        {
            if($str[$i] <> strtolower($str[$i]))
            {
                ++$len;
                ++$upper;
            }

            if($str[$i] <> strtoupper($str[$i]))
                ++$len;
        }
            
        $percent = 0;

        if($len > 0)
            $percent = ($upper/$len) * 100;
            
        return substr($percent , 0 , (($percent > 99) ? 3 : 2));
    }[/code]
Although it's not correct all of the time.

The string "aaaAAA" comes out as 60% caps with that function.

Any help?

Edit: SOLVED!
Link to comment
https://forums.phpfreaks.com/topic/12434-upper-case-char-count/#findComment-47531
Share on other sites

Use this function to do most of the work for you:
[a href=\"http://www.php.net/manual/en/function.count-chars.php\" target=\"_blank\"]http://www.php.net/manual/en/function.count-chars.php[/a]

Then you can use the array_slice() function:
[a href=\"http://www.php.net/manual/en/function.array-slice.php\" target=\"_blank\"]http://www.php.net/manual/en/function.array-slice.php[/a]
[code]$capitalletters = array_slice($charcountarray, ord('A'), 26);[/code]
then you can use this function:
[a href=\"http://www.php.net/manual/en/function.array-sum.php\" target=\"_blank\"]http://www.php.net/manual/en/function.array-sum.php[/a]
[code]$totalcaplets = array_sum($capitalletters);[/code]
--Use a similiar method to get the sum of the small letters. It is not the sum of the count_chars function, that will count punctuation, tabs, line feeds, spaces, and any control characters as well.
Link to comment
https://forums.phpfreaks.com/topic/12434-upper-case-char-count/#findComment-47535
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.