Jump to content

Please Help- Should be easy!


sam06

Recommended Posts

I've been using this code from the scriptplayground:

 

<?php
$file = "text.txt";
$delimiter = ",";
$column = array("Name", "Lastname", "Favorite Transport");

@$fp = fopen($file, "r") or die("Could not open file for reading");
while (!feof($fp))
{
    $tmpstr = fgets($fp, 100);
    $line[] = ereg_replace("\r\n", "", $tmpstr);
}
for ($i=0; $i < count($line); $i++)
{
    $line[$i] = split($delimiter, $line[$i]);
}
?>
<html>
<head>
    <title>Albert's Delimited Text to HTML Table Converter</title>
    <style type="text/css">
        table, body { border-collapse: collapse; font-family: verdana; font-size: 10px; }
    </style>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="0">
    <tr>
<?php
        for ($i=0; $i<count($column); $i++)
            echo "<th>".$column[$i]."</th>";
?>
    </tr>
<?php
for ($i=0; $i < count($line); $i++)
{
    echo "<tr>";
    for ($j=0; $j < count($line[$i]); $j++)
    {
        echo "<td>".$line[$i][$j]."</td>";
    }
    echo "</tr>";
}
fclose($fp);
?>
</table>
</body>
</html> 

 

Unfortunetly, the code input starts of with the delimiter, so the output is all screwed up.

 

Is there a way to set it so the delimiter is accounted for on the start of each line?

 

Many thanks,

Sam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.