Search code examples
phpregexpreg-matchpreg-match-allsubstr

Get part of digit in separate variables


I have number 14969126 and want to separate like

$last_five_digits = 69126;
$rest_of_digits = 149;

I have tried

$last_five_digits = substr($postalcode, -5);

But how can i get rest of the digits.

Please provide any suggestion.

Thank you.


Solution

  • You can use:

    $firstDigits = substr($postalcode, 0, -5);
    //=> 149