i have a PHP function that reads a file into a resulting array. i then need to use the rows in the PHP array to populate an HTML table. the problem is that the rows are a mixture of single elements (header lines) and rows of 5 elements (table columns). i need the single element rows to span across the 5columns where the tabbed data is below. all the data rows (with 5 elements) have a "+" sign in them, meaning that i can test for pos of + sign to determine whether the row is one header or 5 <TD>s. any pointers? i am thinking that JS is the way to go but i am new to that.
FANTASY FOOTBALL LEAGUE ,
TIES LOSE TIES LOSE TIES LOSE ,
COL SAT OCT 8 2011 ,
1. ARIZONA 2. OREGON ST + 1,
3. GEORGIA 4. TENNESSEE U + 1,
5. MIAMI OH 6. ARMY + 1,
7. MISSOURI 8. KANSAS ST + 3,
9. NAVY 10. SOU MISS + 3,
11.ARIZ STATE 12. UTAH + 3,
^^^^that's what the data looks like
all the rows that start with 1. 3. 5. 7.etc,... are the ones that need to
go into 5 columns:
1. // ARIZONA // 2. // OREGON ST // +1
the other rows "TIES LOS...." etc need to center span across the whole table.
// the data without carriage return (*) (a simple preg_replace with PHP)
var data="FANTASY FOOTBALL LEAGUE ,TIES LOSE TIES LOSE TIES LOSE ,,COL SAT OCT 8 2011 ,,1. ARIZONA 2. OREGON ST + 1,3. GEORGIA 4. TENNESSEE U + 1,5. MIAMI OH 6. ARMY + 1,7. MISSOURI 8. KANSAS ST + 3,9. NAVY 10. SOU MISS + 3,11. ARIZ STATE 12. UTAH + 3";
// Progressive replacements by using the regular expressions
var datm=data.replace(/,(\d+\. )/g,'</td></tr>,<tr><td>$1</td><td>').replace(/ (\d+\. )/g,'</td><td>$1</td><td>').replace(/ (\+ \d+)/g,'</td><td>$1</td></tr>');
var datn='<table><tr><td colspan="5">'+datm.replace(/,(?!<)/g,'</td></tr>,<td colspan="5">').replace(/,/g,'')+'</table>';
// The result in form of HTML table
We replace at first the comma followed by one or more digits, a point and a blank, then the single rank numbers, then the + signs. Then the commas not followed by a opening tag to finally remove the commas. Some classe (with the colspan="5") could achieve the look of the table
(*) An other conditions like no comma at the beginning, blank before range number or plus sign, points after range number, never use of + sign (with two blanks) in names ... are necessary (particularly a blank after 11. and before ARIZONA STATE !).
Last edited by 007Julien; 06-21-2012 at 09:52 AM.
Reason: note and errors
thanks a ton. i have not yet managed to master regex. i use grep all the time so i have a limited exposure to it. that being as it is, i think i can make your logic work - if not the actual syntax. i can take each row in the PHP result and wrap it in tags according to whether it needs to span or otherwise, and concat them into one string - voila = table. i'll let you know. thanks again,