I need to split a string by number and by spaces but not sure the regex for that. My code is:
$array = preg_split('/[0-9].\s/', $content);
The value of $content is:
Weight 229.6104534866 g
Energy 374.79170898476 kcal
Total lipid (fat) 22.163422468932 g
Carbohydrate, by difference 13.641848209743 g
Sugars, total 4.3691034101428 g
Protein 29.256342349938 g
Sodium, Na 468.99386390008 mg
Which gives the result:
Array ( [0] => Weight 229.61045348 [1] => g
Energy 374.791708984 [2] => kcal
Total lipid (fat) 22.1634224689 [3] => g
Carbohydrate, by difference 13.6418482097 [4] => g
Sugars, total 4.36910341014 [5] => g
Protein 29.2563423499 [6] => g
Sodium, Na 468.993863900 [7] => mg
) 1
I need to split the text from the number but not sure how, so that:
[0] => Weight
[1] => 229.60145348
[2] => g
and so on...
I also need it to ignore the commas, brackets and spaces where the label is. When using explode I found that 'Total lipid (fat)' instead of being one value separated into 3 values, not sure how to fix that with regex.
When using explode() I get:
[0] => Total
[1] => lipid
[2] => (fat)
but I need those values as one for a label, any way to ignore that?
Any help is very appreciated!
explode()function ?