note 93533 added to function.ctype-space
| From: | gardnerjohng at hotmail dot com | Date: | Tue, 15 Sep 2009 04:00:01 +0000 |
| Subject: | note 93533 added to function.ctype-space | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160568@lists.php.net to get a copy of this message | ||
A function I wrote last night was fairly flexible in terms of detecting whitespace, and even took
into account the pesky non-breaking spaces / zero-width spaces further up the Unicode alphabet.
The benefit here was being able to isolate and identify specific Unicode indices based on their
subrange.
// Returns TRUE if the ASCII value of $string matches a registered whitespace character.
// * This includes non-breaking spaces, zero-width spaces, and any unicode values below 32.
// * $string: Character to identify. If string extends past one character, the value
// is truncated and only the initial character is examined.
function is_whitespace($string){
// Return FALSE if passed an empty string.
if($string == "") return FALSE;
$char = ord($string);
// Control Characters
if($char < 33) return TRUE;
if($char > 8191 && $char < 8208) return TRUE;
if($char > 8231 && $char < 8240) return TRUE;
// Additional Characters
switch($char){
case 160: // Non-Breaking Space
case 8287: // Medium Mathematical Space
return TRUE;
break;
}
return FALSE;
}
----
Server IP: 69.147.83.197
Probable Submitter: 218.214.137.71
----
Manual Page -- http://www.php.net/manual/en/function.ctype-space.php
Edit -- https://master.php.net/note/edit/93533
Del: integrated -- https://master.php.net/note/delete/93533/integrated
Del: useless -- https://master.php.net/note/delete/93533/useless
Del: bad code -- https://master.php.net/note/delete/93533/bad+code
Del: spam -- https://master.php.net/note/delete/93533/spam
Del: non-english -- https://master.php.net/note/delete/93533/non-english
Del: in docs -- https://master.php.net/note/delete/93533/in+docs
Del: other reasons-- https://master.php.net/note/delete/93533
Reject -- https://master.php.net/note/reject/93533
Search -- https://master.php.net/manage/user-notes.php