I'm currently working on a program to analyze the contents of log files and store them in a MySQL db. The problem I'm having at the moment is developing a regular expression to split a string into a clean array that I can use.
<?php
$string = " 7. echosx 15 16 0.9 100027 1350 -3 14152 Nod";
$array = preg_split('/ /', $string);
print_r($array);
?>
The code uses a basic regular expression inorder to split the string by spaces. What I want to do is have it split the string by a dynamic number of spaces.
Basicly when you run the script it returns the following.
Array
(
[0] =>
[1] =>
[2] => 7.
[3] => echosx
[4] =>
[5] =>
[6] =>
[7] =>
[8] => 15
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] => 16
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] => 0.9
[21] =>
[22] =>
[23] =>
[24] =>
[25] => 100027
[26] =>
[27] => 1350
[28] =>
[29] =>
[30] =>
[31] => -3
[32] =>
[33] =>
[34] =>
[35] =>
[36] =>
[37] => 14152
[38] =>
[39] =>
[40] =>
[41] =>
[42] => Nod
)
What I want it to return is this.
Array
(
[0] => 7.
[1] => echosx
[2] => 15
[3] => 16
[4] => 0.9
[5] => 100027
[6] => 1350
[7] => -3
[8] => 14152
[9] => Nod
)