Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question regex expressions help

    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..?

    10x,
    Pavel

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    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..

  • #4
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    something like this?
    PHP Code:
    <?php
    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>';

    ?>
    Last edited by fci; 02-15-2006 at 02:12 PM.

  • #5
    New Coder
    Join Date
    Feb 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Absolute Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •