You are here: Re: [PHP] Testing a String for 'most' Capitalised « PHP « IT news, forums, messages
Re: [PHP] Testing a String for 'most' Capitalised

Posted by "Chris Boget" on 10/10/05 15:52

> Image that there could be a string
> fred
> Fred
> FRED
> First of all I need to know that these are same which I can do with
> strtolower, but how could I tell
> that 'FRED' is 'most captilised?

Iterate through the string and count the number of capitalised letters.
You can do something like this (untested pseudocode)

$myStr = "Fred";
$numOfCapLetters = 0;
$curLetter = '';

for( $i = 0; $i <= strlen( $myStr ); $i++ ) {
$curLetter = $myStr{$i};
if( strtoupper( $curLetter ) == $curLetter ) {
$numOfCapLetters++;

}
}

then just compare the $numOfCapLetters for each string.

thnx,
Chris

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация