function _image_captcha_utf8_split in CAPTCHA 7
Same name and namespace in other branches
- 8 image_captcha/image_captcha.module \_image_captcha_utf8_split()
- 5.3 image_captcha/image_captcha.module \_image_captcha_utf8_split()
- 6.2 image_captcha/image_captcha.module \_image_captcha_utf8_split()
- 6 image_captcha/image_captcha.module \_image_captcha_utf8_split()
Helper function for splitting an utf8 string correctly in characters.
Assumes the given utf8 string is well formed. See http://en.wikipedia.org/wiki/Utf8 for more info
3 calls to _image_captcha_utf8_split()
- image_captcha_captcha in image_captcha/
image_captcha.module - Implements hook_captcha().
- _image_captcha_image_generator_print_string in image_captcha/
image_captcha.user.inc - Helper function for drawing text on the image.
- _image_captcha_image_size in image_captcha/
image_captcha.module - Helper function for calculating image height and width based on given code and current font/spacing settings.
File
- image_captcha/
image_captcha.module, line 110 - Implements image CAPTCHA for use with the CAPTCHA module
Code
function _image_captcha_utf8_split($str) {
$characters = array();
$len = strlen($str);
for ($i = 0; $i < $len;) {
$chr = ord($str[$i]);
// One byte character (0zzzzzzz)
if (($chr & 0x80) == 0x0) {
$width = 1;
}
else {
// Two byte character (first byte: 110yyyyy)
if (($chr & 0xe0) == 0xc0) {
$width = 2;
}
elseif (($chr & 0xf0) == 0xe0) {
$width = 3;
}
elseif (($chr & 0xf8) == 0xf0) {
$width = 4;
}
else {
watchdog('CAPTCHA', 'Encountered an illegal byte while splitting an utf8 string in characters.', array(), WATCHDOG_ERROR);
return $characters;
}
}
$characters[] = substr($str, $i, $width);
$i += $width;
}
return $characters;
}