devolve_absolve wrote in php 🤓geeky

Listens: Slipknot - Before I Forget

EDIT: My bad, I forgot about the easy way. Yeah, I know, me stupid =D


Can anyone give me a pointer on how to cut this down? I've been messing with regex for a few days, and this is what I have come up with. The general idea is to cut down a string into blocks of 5. The string could be 5 characters long, it could be 500, it doesn't matter, I just need to break it down into groups.



$num = "12345678905432109876";
$numarray = array();

while (strlen($num) > 5) {

preg_match('/(.{5})(\d )/',$num,$match);

$num = $match[2];
$numarray[] = $match[1];

if (strlen($num) == 5) {
$numarray[] = $match[2];
}

}