473,322 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

determine of part of string is uppercase, based on requirements

<?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.

Oct 27 '07 #1
6 5648
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. help 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()
Oct 27 '07 #2
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;
}

Oct 27 '07 #3
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


Oct 27 '07 #4
18****@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.
Why not use the nice consise regex that Rik gave you over on
comp.databases.mysql when you asked almost the same question!
Oct 28 '07 #5
On Sun, 28 Oct 2007 16:29:43 +0100, Rik Wasmus
<lu************@hotmail.comwrote:
and in UTF-8 mode use this pattern:
'/\b\w*?\p{Lu}{2,}\w*?\b/'
Euhm, '/\b\w*?\p{Lu}{2,}\w*?\b/u' offcourse....
--
Rik Wasmus
Oct 28 '07 #6
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 helpfully connecting to. best wishes

Oct 28 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: José Carlos | last post by:
Hi. How can i part a big string to block of information of (4Kb for example).? i´m trying send it from a socket client to server and how can i calculate the time it´s coming. Thank you. ...
8
by: Markus Dehmann | last post by:
My ios::uppercase (and others) seems not to work. #include <iostream> using namespace std; int main(){ int num = 45; cout.setf(ios::hex | ios::showbase | ios::uppercase); cout << "number " <<...
1
by: Matthew | last post by:
Hey, I have built a form that has certain combo and text boxes on it, which a user specifies his criteria and then clicks on a search button to run a query based on that criteria. To build to...
6
by: lisa.lin | last post by:
Hi,all Is there any library function to tell a string to be a number? I did't find it in <string.h>, does anyone kow? Thanks in advance! Lisa Lin
3
by: xianxian | last post by:
Hi guys, I'm having trouble getting my Datagrid to display according to Checkboxes checked values. On my Checkboxes, I have 5 values :- 1) Apartment/Condo 2) Executive Condo 3) Detached 4)...
2
by: TCB | last post by:
How can I separate multiple email addresses entered in a single textbox so I can send email in ASP.NET 2.0, the email addresses are separated by (,) or (;) Thanks
2
by: Monkey | last post by:
Hi, Just coming back to perl after some time off, I think I need to use the split funtion. I want to convert $username=FEL\matt.honston, to $username=matt.honston and remove or split the FEL\...
3
by: shapper | last post by:
Hello, How can I make the first letter of a string to be upper case and all the others lower case? Thanks, Miguel
2
by: rienh | last post by:
Hello all, I try to accomplish the following. I have a string like: “volkswagen-golf-gti” ** And I want it to change the string into: “Volkswagen Golf GTI” (last part completely uppercase) But...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.