Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1021503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:19:14+00:00 2026-05-16T11:19:14+00:00

php newbie here..I need some PHP help ideas/examples on how to import data from

  • 0

php newbie here..I need some PHP help ideas/examples on how to import data from a delimited text file and map them into html tables. The data should populate and be mapped under its proper header. There are instances also where each record doesn’t have all the values and if no data, then we can leave it null (See sample records). I would also create a table row entry for each record.

For example, the input/source file has these entries: (they are prefixed by a number to represent the header in the html table. So data from “1-MyServer” is “server4.mra.dev.pp1” and should be under table header “Server” for example. There are instances also where the record doesn’t have all the values (1-7) (See below):

1-MyServer=server4.mra.dev.pp1;2-MyLogdate=Wed Aug 11 2010;3-MyDataset=dbip.pp1;4-MyStartTime=01:00:03;5-MyDuration=00:36:09;6-MySize=41.54 GB;7-MyStatus=Succeeded;
1-MyServer=server9.mra.dev.kul;2-MyLogdate=Wed Aug 11 2010;3-MyDataset=gls202.kul_lvm;5-MyDuration=06:20:33;7-MyStatus=Succeeded;
1-MyServer=server9.mra.dev.kul;2-MyLogdate=Wed Aug 11 2010;3-MyDataset=gls101.aie_lvm;4-MyStartTime=01:00:02;

Here is a copy of my html table that I would need it to map it too:
(Also, I would not have to populate record for “2-MyLogdate” into a header)

<table id="stats">
tr>
  <th>Server</th>
  <th>Set</th>
  <th>Start</th>
  <th>Duration</th>
  <th>Size</th>
  <th>Status</th>
</tr>
<tr>
<td>server4.mel.dev.sp1</td>
<td>dbip.sp1</td>
<td>01:00:03</td>
<td>00:36:09</td>
<td>41.54 GB</td>
<td>Succeeded</td>
</tr>
</table>

So what I really need is a system to map these appropriately.
How would I write this in php?? Thanks!

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:19:14+00:00Added an answer on May 16, 2026 at 11:19 am

    It’s all about finding the patterns in your files. In your example, it’s rather easy:

    [number]-[column name]=[value];
    

    The main problem I see is that you have redundant information: the number of the column, and the columns themselves, which are repeated for every row. You can parse them away, though. It depends on what you expect from your program: will the columns order always be the same? Will there always be the same columns? How should you react to unknown columns?

    Here’s a quick example of what you could do, using regular expressions. This example assumes that column names are all the same, and that you want to display them all, and that they’ll always be in the same order. In other words, I’m doing it the easy way.

    $data = array();
    
    $lines = file("my/log/file.log");
    // this will parse every line into an associative array, discarding the header number
    foreach ($lines as $line)
    {
        // populate $matches with arrays where indices are as follows:
        // 0: the whole string (0-Foo=bar;)
        // 1: the column number (0)
        // 2: the column name (Foo)
        // 3: the value (Bar)
        preg_match_all("/([0-9])-([^=]+)=([^;]+);/", $line, $matches, PREG_SET_ORDER);
        $lineData = array();
        foreach ($matches as $information)
            $lineData[$information[2]] = $information[3];
        $data[] = $lineData;
    }
    
    $keys = array_keys($data[0]); // you can also set this yourself
    // for instance, $keys = array('MyServer', 'MyDataset'); would only display those two columns
    echo '<table><tr>';
    foreach ($keys as $column)
        echo '<th>' . $column . '</th>';
    echo '</tr>';
    
    foreach ($data as $row)
    {
        echo '<tr>';
        foreach ($keys as $column)
            echo '<td>' . (isset($row[$column]) ? $row[$column] : '') . '</td>';
        echo '</tr>';
    }
    echo '</table>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a PHP newbie working a some scripts to display some news articles from
PHP/MySQL newbie here. I managed to develop a web page that displays info from
newbie at php here, basically I wish to know how to add data to
I need a little help. Im a newbie. I'm trying to create a php
Newbie here trying to maintain a PHP website for some charity organization, but cannot
A really php newbie here, sorry if the question is too simple. I’m following
a bit of a PHP / MySQL newbie here... I've been building a PHP-based
Im sure this is simple but newbie here. I have 5 URLS cards.php&type=one cards.php&type=two
I'm a newbie to sql and am trying to follow this example here: http://net.tutsplus.com/tutorials/php/a-better-login-system/
Im a newbie ih php.Im trying to show drop down list values from database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.