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 182719 on 10/27/07 22:05

> you could use
>
> ereg( '^[a-zA-Z0-9]*[A-Z]{2,}[a-zA-Z0-9]*$', $testcase );
>

Thank you all so much. I am more of a big fan of ereg for its
elegance, however being cryptic and hard to learn!

This is what I am working with, ...


<?

$testcase = "This should be CaUGht in filter";

print "Testing string > " . $testcase . "<br><br>";

if (ereg( '^[a-zA-Z0-9]*[A-Z]{2,}[a-zA-Z0-9]*$', $testcase ))
{
print "TWO OR MORE CONSECUTIVE UPPERCASE LETTERS";
} else {
print "NO CONSECUTIVE UPPERCASE LETTERS";
}

?>

2 other questions if possible:

1) How to ignore any # of spaces? See how my running test program
doesn't catch the double uppercase on the second word. Some of my
data unfortunately has 2 or more spaces in the strings, so it may be 2
or 3 spaces between words that would need to be ignored ... (separate
issue which I can tackle)... don't want to confuse things. It would
be cool if we could eliminate those extra spaces beyond 1 (see below).

2) How to in situations where two or more consecutive letters are
found, to lowecase them EXCEPT 1) if it is a first letter, then it
should keep it uppercase... and lowercase the remaining letters of the
word. What has my head swimming is the space issues,.... if they are
being ignored.

Like, should work this way:

$testcase = "Hello World" ; < passes no problem OK
$testcase = "HEllo WOrld" ; < should be transformed to "Hello World"
$testcase = "HeLLo WORLD" ; < should be transformed to "Hello World"
$testcase = "Hello wORld" ; < should be transformed to "Hello
world" :) No problem

I guess some things would slip through, but my data isn't that
irregular, like "Hello WoRld" would technically be OK even though it's
wrong, ... but I don't think I have strange situations like that.

Just trying to save some time and energy I hope you understand :)

I've got tons of data, and this is something that will save me years
of my life. Ok, many many weeks of hard labor :) Thank you soo much
for the assistance so far.

best wishes

 

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

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