Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

w2ksp4.exe, WwwxxXdbf, procmail "FROM_MAILER" patch, Use of assignment to $[ is deprecated at /usr/local/sbin/apxs line 86. , wwwxxx vim, mysql closing table and opening table, 800c5000, setgid operation not permitted, pciehp: acpi_pciehprm on IBM, WWWXXX.DBF

Links

XODOX
Impressum

#1: determine of part of string is uppercase, based on requirements

Posted on 2007-10-27 22:39:27 by 182719

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

Report this message

#2: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-27 22:58:28 by shimmyshack

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()

Report this message

#3: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-27 22:58:28 by shimmyshack

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()

Report this message

#4: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-27 22:58:39 by zeldorblat

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;
}

Report this message

#5: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-27 22:58:39 by zeldorblat

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;
}

Report this message

#6: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-28 00:05:47 by 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 . "<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

Report this message

#7: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-28 00:05:47 by 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 . "<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

Report this message

#8: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-28 15:42:51 by Paul Lautman

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

Report this message

#9: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-28 15:42:51 by Paul Lautman

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

Report this message

#10: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-28 16:29:43 by 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 <?php where possible instead of <?. Search the group archives or
google why (searchterm: short_open_tags).

> $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 ))

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

Report this message

#11: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-28 17:03:32 by luiheidsgoeroe

On Sun, 28 Oct 2007 16:29:43 +0100, Rik Wasmus
<luiheidsgoeroe@hotmail.com> 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

Report this message

#12: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-28 17:17:11 by 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

Report this message

#13: Re: determine of part of string is uppercase, based on requirements

Posted on 2007-10-28 17:17:11 by 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

Report this message