determine of part of string is uppercase, based on requirements
determine of part of string is uppercase, based on requirements
am 27.10.2007 22:39:27 von 182719
$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.
Re: determine of part of string is uppercase, based on requirements
am 27.10.2007 22:58:28 von shimmyshack
On Oct 27, 9:39 pm, 182...@rock.com wrote:
>
>
> $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()
Re: determine of part of string is uppercase, based on requirements
am 27.10.2007 22:58:28 von shimmyshack
On Oct 27, 9:39 pm, 182...@rock.com wrote:
>
>
> $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()
Re: determine of part of string is uppercase, based on requirements
am 27.10.2007 22:58:39 von zeldorblat
On Oct 27, 4:39 pm, 182...@rock.com wrote:
>
>
> $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;
}
Re: determine of part of string is uppercase, based on requirements
am 27.10.2007 22:58:39 von zeldorblat
On Oct 27, 4:39 pm, 182...@rock.com wrote:
>
>
> $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;
}
Re: determine of part of string is uppercase, based on requirements
am 28.10.2007 00:05:47 von 182719
> 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 . "
";
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
Re: determine of part of string is uppercase, based on requirements
am 28.10.2007 00:05:47 von 182719
> 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 . "
";
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
Re: determine of part of string is uppercase, based on requirements
am 28.10.2007 15:42:51 von Paul Lautman
182719@rock.com wrote:
>
>
> $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!
Re: determine of part of string is uppercase, based on requirements
am 28.10.2007 15:42:51 von Paul Lautman
182719@rock.com wrote:
>
>
> $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!
Re: determine of part of string is uppercase, based on requirements
am 28.10.2007 16:29:43 von luiheidsgoeroe
On Sun, 28 Oct 2007 00:05:47 +0200, <182719@rock.com> wrote:
>> 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!
>
>
Use
google why (searchterm: short_open_tags).
> $testcase = "This should be CaUGht in filter";
>
> print "Testing string > " . $testcase . "
";
>
> if (ereg( '^[a-zA-Z0-9]*[A-Z]{2,}[a-zA-Z0-9]*$', $testcase ))
Should this not BE caught in the filter? One should use the PCRE (preg_*)
functions, and the match should not be greedy as in the patter above.
> 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
As indicated elsewhere, indentify the records in need of substitution in
your database using the answer givne in comp.databases.mysql
For those that do need substitution:
function _my_replace_function($match){
$return = substr($match[0],0,1); //first character stays the same
$return .= strtolower(substr($match[0],1)); //the rest should be lowercase
return $return;
}
$string =
preg_replace_callback('/\b\w*?[A-Z]{2,}\w*?\b/','_my_replace _function',$string);
Ideally, one should use a proper locale, substitute strtolower with
mb_strtolower and in UTF-8 mode use this pattern:
'/\b\w*?\p{Lu}{2,}\w*?\b/'
.... to be able to capture and change capitals like 'wÉÏrd' (which are not
in the normal [A-Z] range).
(my newsserver doesn't carry alt.php, dropped)
--
Rik Wasmus
Re: determine of part of string is uppercase, based on requirements
am 28.10.2007 17:03:32 von luiheidsgoeroe
On Sun, 28 Oct 2007 16:29:43 +0100, Rik Wasmus
wrote:
> 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
Re: determine of part of string is uppercase, based on requirements
am 28.10.2007 17:17:11 von 182719
> 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
Re: determine of part of string is uppercase, based on requirements
am 28.10.2007 17:17:11 von 182719
> 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