note 76746 added to function.count-chars
| From: | pzb at novell dot com | Date: | Sun, 29 Jul 2007 01:29:57 +0000 |
| Subject: | note 76746 added to function.count-chars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129014@lists.php.net to get a copy of this message | ||
This function is great for input validation. I frequently need to check that all characters in a
string are 7-bit ASCII (and not null). This is the fastest function I have found yet:
<?php
function is7bit($string) {
// empty strings are 7-bit clean
if (!strlen($string)) {
return true;
}
// count_chars returns the characters in ascending octet order
$str = count_chars($str, 3);
// Check for null character
if (!ord($str[0])) {
return false;
}
// Check for 8-bit character
if (ord($str[strlen($str)-1]) & 128) {
return false;
}
return true;
}
?>
----
Server IP: 66.207.199.35
Probable Submitter: 206.248.138.140
----
Manual Page -- http://www.php.net/manual/en/function.count-chars.php
Edit -- https://master.php.net/note/edit/76746
Del: integrated -- https://master.php.net/note/delete/76746/integrated
Del: useless -- https://master.php.net/note/delete/76746/useless
Del: bad code -- https://master.php.net/note/delete/76746/bad+code
Del: spam -- https://master.php.net/note/delete/76746/spam
Del: non-english -- https://master.php.net/note/delete/76746/non-english
Del: in docs -- https://master.php.net/note/delete/76746/in+docs
Del: other reasons-- https://master.php.net/note/delete/76746
Reject -- https://master.php.net/note/reject/76746
Search -- https://master.php.net/manage/user-notes.php