php - Split string into array then loop into HTML table -
i have string extracted database in example below. i'm trying loop through string html table display results in diagram. string can vary in length follow same format.
$string = "18/05-01/06 01/06-06/07 06/07-22/08 22/08-14/09 dr record + 2 21.47 20.24 27.15 20.24 record + 2 24.05 22.68" _______________________________________________________________________ |18/05-01/06 | 01/06-06/07 | 06/07-22/08 | 22/08-14/09 | _______________________________________________________________________ dr record + 2 | 21.47 | 20.24 | 27.15 | 20.24 | _______________________________________________________________________ record + 2 | 24.05 | 22.68 | | | _______________________________________________________________________
everything i've tried doesn't seem work. ideas appreciated.
this i've tried far
$string = "18/05-01/06 01/06-06/07 06/07-22/08 22/08-14/09 dr record + 2 21.47 20.24 27.15 20.24 record + 2 24.05 22.68" $parts = preg_split('/\s+/', $string ); $date = array(); $record = array(); $price = array(); foreach($parts $part) { // check date if(strpos($part,'-') !== false) { $date[] = $part; } // check price elseif(strpos($part, '+') !== false) { $record[] = $part; } // echeck record elseif(strpos($part, '.') !== false) { $price[] = $part; } }
$parts = preg_split('/\s+/', $string ); //it returns array
Comments
Post a Comment