Best way to explode the following

Hi guys,

I need help

i need a way to do the following enter a ref so say 14-111222 what i would like to do is break up this to sections

so 14 would be one and then 111 would be another and then 222 would be another.

could any one help me work this out please.


<?php

$code = '14-111222';
$parts = explode('-', $code);
$marker_one = $parts[0];
$marker_two = substr($parts[1], 0, 3);
$marker_three = substr($parts[1], 3);
echo '<pre>';
var_dump($marker_one, $marker_two, $marker_three);

The ony condition for this to work is to have the “111” part of 3 chars.
Always! Else, you cannot extract it.

i’ve just done the following code


<?php 
$code = '14-111222'; 
$parts = explode('-', $code); 
$marker_one = $code[0]; 
$marker_two = substr($code[1], 0, 3); 
$marker_three = substr($code[1], 3);

echo $marker_one;
echo $marker_two;
echo $marker_three;

but only marker one is echo’d

so that marker one would 1 and marker 2 nothing is echo’d for marker three

I did a mistake and corrected, while you where writing your post :slight_smile:
instead of $code[ must be $parts[

Now the code is changed and should work

you sir are a legend.

thank you very much for your help :slight_smile: