PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > determine of part of string is uppercase, based on requirements
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
determine of part of string is uppercase, based on requirements

Réponse
 
LinkBack Outils de la discussion
Vieux 27/10/2007, 21h39   #1
182719@rock.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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. me?

Thank you in advance for assistance. Have a very good day.

  Réponse avec citation
Vieux 27/10/2007, 21h58   #2
shimmyshack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: determine of part of string is uppercase, based on requirements

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


  Réponse avec citation
Vieux 27/10/2007, 21h58   #3
ZeldorBlat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: determine of part of string is uppercase, based on requirements

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

  Réponse avec citation
Vieux 27/10/2007, 23h05   #4
182719@rock.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: determine of part of string is uppercase, based on requirements

> 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




  Réponse avec citation
Vieux 28/10/2007, 15h42   #5
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: determine of part of string is uppercase, based on requirements

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!


  Réponse avec citation
Vieux 28/10/2007, 17h17   #6
182719@rock.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: determine of part of string is uppercase, based on requirements


> 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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17657 seconds with 14 queries