You are here: Re: determine of part of string is uppercase, based on requirements « All PHP « IT news, forums, messages
Re: determine of part of string is uppercase, based on requirements

Posted by ZeldorBlat on 10/27/07 20:58

On Oct 27, 4:39 pm, 182...@rock.com wrote:
> <?php
>
> $testcase = 'AKLWC139';
>
> if (ctype_upper($testcase)) {
> echo "The string $testcase consists of all uppercase letters.
> \n";
> } else {
> echo "The string $testcase does not consist of all uppercase
> letters.\n";
> }
>
> ?>
>
> This is some code that will check a string and validate if it consists
> of all uppercase letters. I am not too familiar with syntax of PHP as
> I am learning, ... can someone please show me a way to make this, so
> it dives a little deeper into checking, and instead checks to see if
> part of the string contains two or more consecutive uppercase
> letters? Like
>
> 'akwSKWsm' would return positive,.... but 'aKwskWsm' would not.
>
> I don't know how this would work, but it seems approachable. Can
> someone pls. help me?
>
> Thank you in advance for assistance. Have a very good day.

Try this (untested):

function foo($str) {
$len = strlen($str);
$prevIsUpper = false;

for($i = 0; $i < $len; $i++) {
if(ctype_upper($str[$i]) && $prevIsUpper)
return true;

$prevIsUpper = ctype_upper($str[$i]);
}

return false;
}

 

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

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