4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 PHP: ALL IN CAPITALS
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sat Feb 15, 2003 5:49 pm (14 years, 10 months ago) Reply with QuoteBack to Top

How can I detect if more then 50% of a string has been written in capitals?
I want to prevent excessive capitals in my chat room.

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
verto
Senior WebHelper
Senior WebHelper


Joined: 14 Jan 2002
Posts: 220
Location: Cambridge MA USA

PostPosted: Sun Feb 16, 2003 3:40 am (14 years, 10 months ago) Reply with QuoteBack to Top

Something with regular expressions would be my first approach -- then compare the size of the two strings.

________________________________
>>>>>>>>>>>>>
GENERAL DISCLAIMER:This disclaimer may be void where null in all cases unless explicitly not unprohibited or (p)re-exclusively assigned by sufficient presedimentation on behalf of every non-interested party to wit (or so it was said).
:::
.: :. . : :....: :.: .: :. verto .: :. . : :....: :.: .: :.
OfflineView User's ProfileFind all posts by vertoSend Personal Message
jatonline
Junior WebHelper
Junior WebHelper


Joined: 21 Dec 2002
Posts: 5
Location: Gloucestershire, UK

PostPosted: Mon Feb 17, 2003 5:42 pm (14 years, 10 months ago) Reply with QuoteBack to Top

verto wrote:
Something with regular expressions would be my first approach -- then compare the size of the two strings.


Does this help??

Code:
<?php

$str_to_test = 'HELlo;

$no_caps = preg_replace('/[A-Z]/', '', $str_to_test);

if((strlen($str_to_test) / 2) > strlen($no_caps)) {

   echo 'over half caps';

} else {

   echo 'half or less caps';

}

?>

________________________________
James Thomas (personal site)
Giving Up on the Ordinary (blog)
OfflineView User's ProfileFind all posts by jatonlineSend Personal MessageVisit Poster's Website
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.053571 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme