View Full Version : regex expressions help

02-14-2006, 09:25 PM
To those familiar with the syntax...
Could you please help me in setting up an expression for the function preg_match_all which is parsing a file named "file.txt":

Every line from that file has to be in different <TR> of a table.
There are 7 couples of words on each line of the file which are all seperated by a TAB space. Every one of these couples of words has to be located on a separate <TD> of that <TR>

what should the expression be in order to have such an effect..?


02-14-2006, 11:13 PM
Im a bit confused, does the file.txt have the TR and TD tags in? Or are you trying to put some data seperated by tabs into an html table?

02-15-2006, 02:34 PM
YES! I would like to make the script parse the .txt file and create a table from its contents, putting <TD> where it catches a TAB delimiter... and respectively add a <TR> where is catches a NEW LINE..

02-15-2006, 03:10 PM
something like this?

function convert_to_table($line) {
return '<tr><td>'.str_replace("\t", '</td><td>', $line).'</td></tr>';

function tabfile_to_rows($file) {
return implode('', array_map('convert_to_table', file($file)));

echo '<table>'.tabfile_to_rows('test.txt').'</table>';


02-15-2006, 03:59 PM
Absolute Thanks!