I am trying to break a string of binary ones and zeros into groups of four. After reading the manual and the posts I am missing something:
$subject = "101010101";
$pattern = "/.{1,4}/";
$blocks = preg_split ($pattern, $subject);
print_r($blocks);
The result is an empty array.
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
)
php >
preg_split()uses theregexto identify the delimiter. You don't needregexfor this job,str_split()is better because it is faster (and easier to understand).