3 * Replace str_split()
\r
6 * @package PHP_Compat
\r
7 * @license LGPL - http://www.gnu.org/licenses/lgpl.html
\r
8 * @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
\r
9 * @link http://php.net/function.str_split
\r
10 * @author Aidan Lister <aidan@php.net>
\r
11 * @version $Revision: 1.1 $
\r
13 * @require PHP 4.0.0 (user_error)
\r
15 function php_compat_str_split($string, $split_length = 1)
\r
17 if (!is_scalar($split_length)) {
\r
18 user_error('str_split() expects parameter 2 to be long, ' .
\r
19 gettype($split_length) . ' given', E_USER_WARNING);
\r
23 $split_length = (int) $split_length;
\r
24 if ($split_length < 1) {
\r
25 user_error('str_split() The length of each segment must be greater than zero', E_USER_WARNING);
\r
29 // Select split method
\r
30 if ($split_length < 65536) {
\r
31 // Faster, but only works for less than 2^16
\r
32 preg_match_all('/.{1,' . $split_length . '}/s', $string, $matches);
\r
35 // Required due to preg limitations
\r
39 $len = strlen($string);
\r
42 $blk = ($len < $split_length) ? $len : $split_length;
\r
43 $arr[$idx++] = substr($string, $pos, $blk);
\r
54 if (!function_exists('str_split')) {
\r
55 function str_split($string, $split_length = 1)
\r
57 return php_compat_str_split($string, $split_length);
\r