Re: [PHP] Testing a String for 'most' Capitalised
Greg Donald wrote: On 10/10/05, Jochem Maas <[EMAIL PROTECTED]> wrote: I AM NOT THE OP THANKS, I'm quite capable of solving such a problem without the help of people who don't bother to think beyond 'sample data' ... Yeah, everyone should read minds automatically, I agree. I guess reading the question was out of the question? and as for me not being the OP - might I suggest a decent new reader or mail client so you can actually view the thread structure? It's bloody obvious that the data in question (sample or not) will not be in an order that means the string with the most capital letters will be 'top of the list' after a sort(). No sense in getting your panties in a bloody wad. Did I say that right? I so rarely get to use 'bloody' in programming conversation. you didn't say that right IFAICT. try exchanging 'wad' for 'panties' - now you have an idiom. The code I posted works with the sample data provided. Sorry if it right. but it doesn't answer the question, so you have probably confused the OP (or the confusion will arise some four weeks after having implemented your suggestion when he realises _something_ is not working as it should) - although given the direction of this thread he has no more excuse for not knowing that your cute trick will get him into 'trouble'. bothers you that I didn't test it with a full dictionary word list. the oxford abridged version would have sufficed. ;-) *shrug* is rather blasee btw. http://dictionary.reference.com/search?q=blasee Blase? Why yes.. that's me in a nutshell. my point being that 'blase' is not a positive attribute for an engineer. we can agree to disagree on that one though! "the blase NASA launch engineer didn't bother to check the fuel line all the way through because it had passed all the checks on a previous run." "BOOM" -- Greg Donald Zend Certified Engineer MySQL Core Certification http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing a String for 'most' Capitalised
On 10/10/05, Jochem Maas <[EMAIL PROTECTED]> wrote: > I AM NOT THE OP THANKS, I'm quite capable of solving > such a problem without the help of people who don't bother > to think beyond 'sample data' ... Yeah, everyone should read minds automatically, I agree. > It's bloody obvious that > the data in question (sample or not) will not be in an order > that means the string with the most capital letters will be > 'top of the list' after a sort(). No sense in getting your panties in a bloody wad. Did I say that right? I so rarely get to use 'bloody' in programming conversation. The code I posted works with the sample data provided. Sorry if it bothers you that I didn't test it with a full dictionary word list. > *shrug* is rather blasee btw. http://dictionary.reference.com/search?q=blasee Blase? Why yes.. that's me in a nutshell. -- Greg Donald Zend Certified Engineer MySQL Core Certification http://destiney.com/
Re: [PHP] Testing a String for 'most' Capitalised
Greg Donald wrote: On 10/10/05, Jochem Maas <[EMAIL PROTECTED]> wrote: cute - but it doesn't always work e.g.: $a = array( "FrEDDie", "fREDdIE", "FReddie" ); sort( $a ); echo $a[ 0 ]; // we want the 2nd item from the unsort array Works for the sample data you first posted. *shrug* I AM NOT THE OP THANKS, I'm quite capable of solving such a problem without the help of people who don't bother to think beyond 'sample data' ... It's bloody obvious that the data in question (sample or not) will not be in an order that means the string with the most capital letters will be 'top of the list' after a sort(). *shrug* is rather blasee btw. -- Greg Donald Zend Certified Engineer MySQL Core Certification http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing a String for 'most' Capitalised
On 10/10/05, zzapper <[EMAIL PROTECTED]> wrote: > Hi, > > 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? strlen(preg_replace('/[^[:upper:]]/', '', $b)) ? $a : $b; } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing a String for 'most' Capitalised
On 10/10/05, Jochem Maas <[EMAIL PROTECTED]> wrote: > cute - but it doesn't always work e.g.: > > $a = array( "FrEDDie", "fREDdIE", "FReddie" ); > sort( $a ); > echo $a[ 0 ]; // we want the 2nd item from the unsort array Works for the sample data you first posted. *shrug* -- Greg Donald Zend Certified Engineer MySQL Core Certification http://destiney.com/
Re: [PHP] Testing a String for 'most' Capitalised
Greg Donald wrote: On 10/10/05, zzapper <[EMAIL PROTECTED]> wrote: 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 $a = array( 'fred', 'Fred', 'FRED' ); sort( $a ); echo $a[ 0 ]; cute - but it doesn't always work e.g.: $a = array( "FrEDDie", "fREDdIE", "FReddie" ); sort( $a ); echo $a[ 0 ]; // we want the 2nd item from the unsort array -- Greg Donald Zend Certified Engineer MySQL Core Certification http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing a String for 'most' Capitalised
> > Image that there could be a string > > fred > > Fred > > FRED It isn't hard to do. > > First of all I need to know that these are same which I can do with > > strtolower Also note strcasecmp for this task - http://uk2.php.net/manual/en/function.strcasecmp.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Testing a String for 'most' Capitalised
On 10/10/05, zzapper <[EMAIL PROTECTED]> wrote: > 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 $a = array( 'fred', 'Fred', 'FRED' ); sort( $a ); echo $a[ 0 ]; -- Greg Donald Zend Certified Engineer MySQL Core Certification http://destiney.com/
Re: [PHP] Testing a String for 'most' Capitalised
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php