-2

I have a string and this string should be an array.

But the first 2 letters are variable and I need the 5 next digits (whether empty or not). The last 5 digits are numeric with a decimal point or empty ( $string="AB3 . ";)

An example:

$string = "AB10.00";

$arr[0] = "AB";
$arr[1] = "10.00";

I would like to use preg_split() for this.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
JasperM
  • 57
  • 1
  • 1
  • 6

1 Answers1

2

You mean substr() ?

$string = "AB10.00";
$arr[0] = substr($string, 0, 2); // $arr[0] == 'AB'
$arr[1] = substr($string, 2); // $arr[1] == '10.00'
Thomas Ruiz
  • 3,611
  • 2
  • 20
  • 33
  • `$arr[1] = substr($string, 2, 6);` since OP is after last 5 digits (5+1 for the decimal point). Or does it need to work out whether there is a decimal point? – Alex Hadley Dec 11 '12 at 15:17
  • I didn't specify the length for the second substr because I couldn't figure if the point was part of the 5 digits or not. – Thomas Ruiz Dec 11 '12 at 15:24
  • yes thanks, substr() sorry but, i don't see the forest for the trees. – JasperM Dec 11 '12 at 15:27