473,772 Members | 3,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

determine of part of string is uppercase, based on requirements

<?php

$testcase = 'AKLWC139';

if (ctype_upper($t estcase)) {
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 5678
On Oct 27, 9:39 pm, 182...@rock.com wrote:
<?php

$testcase = 'AKLWC139';

if (ctype_upper($t estcase)) {
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($t estcase)) {
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($st r[$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($t estcase)) {
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.comwro te:
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
1377
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. Regards.
8
4318
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 " << num << endl; return 0; }
1
4189
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 this, I want to add check boxes on this form, with the names of some of the fields in my query, where if unchecked, the query will still run like before, but will not show the unchecked fields anymore. Can I do this?
6
2634
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
1589
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) Semi-detached
2
1411
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
2503
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\ from the string (yes I'm using the whoaim command in XP) I know I need to use the split function, but just can't to remember the syntax. Thanks,
3
3511
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
4472
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 I have some difficulties understanding preg_replace. Right now I have the following code: <?php $string = 'volkswagen-golf-gti';
0
9620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.