Link to home
Start Free TrialLog in
Avatar of DrZork101
DrZork101

asked on

Splitting string into varying length chunks

Hi,

I have a string e.g.

$string = "123ES4GYT6889";

Open in new window


which is always going to be the same length.

I want to split it in the same way each time - the first 3 characters, then the next 6, then the next 3.

What is the most efficient way of doing this?

Thanks,

Julian

Avatar of LLMorrisson
LLMorrisson
Flag of United States of America image

$chunk1 = substr($str, 0, 3);
$chunk2 = substr($str, 3, 6);
$chunk3 = substr($str, 9, 3);
SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial