|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
<?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. me? Thank you in advance for assistance. Have a very good day. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Oct 27, 9: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. me? > > Thank you in advance for assistance. Have a very good day. you need ereg() or one of the preg_ regular expressions, google for "ereg php function" to see many examples of its power. you could use ereg( '^[a-zA-Z0-9]*[A-Z]{2,}[a-zA-Z0-9]*$', $testcase ); this means at the start of testcase ^ zero ore more * characters of type a-z or A-Z or 0-9 followed by 2 or more {2,} characters within A-Z range ended $ by zero or more a-z A-Z or 0-9 characters. you can even make SURE that the conditions are complied with by using ereg_replace() |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. 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; } |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
> 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 problemI 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 muchfor the assistance so far. best wishes |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
182719@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. me? > > Thank you in advance for assistance. Have a very good day. Why not use the nice consise regex that Rik gave you over on comp.databases.mysql when you asked almost the same question! |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
> Why not use the nice consise regex that Rik gave you over on > comp.databases.mysql when you asked almost the same question! Actually I am leveraging that bright person over there, but so far it doesn't actually fully achieve the goals presented over here in this group you are fully connecting to. best wishes |
|
![]() |
| Outils de la discussion | |
|
|