|
Author |
Message |
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sat Feb 15, 2003 5:49 pm (21 years, 2 months ago) |
|
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 |
|
|
|
verto
Senior WebHelper
Joined: 14 Jan 2002
Posts: 220
Location: Cambridge MA USA
|
Posted:
Sun Feb 16, 2003 3:40 am (21 years, 2 months ago) |
|
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 .: :. . : :....: :.: .: :. |
|
|
|
jatonline
Junior WebHelper
Joined: 21 Dec 2002
Posts: 5
Location: Gloucestershire, UK
|
Posted:
Mon Feb 17, 2003 5:42 pm (21 years, 2 months ago) |
|
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) |
|
|
|
|
|
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.120864 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |