Jump to content

A ‘Data Driven’ Page


Dr Ben Warne

Recommended Posts

For this code below

<html>
<head>
</head>
<body>
<table>
<tr>
<th>Headlines</th><th>Message of the Day</th>
</tr>
<tr>
<td width='50%'>Column One</td>
<td width='*'>
<?php
    $filename = 'text.txt';
    $array_of_lines  = file($filename);
    foreach($array_of_lines as $line)
    print $line;
?>
</td>
</tr>
</table>
</body>
</html>

I want to permit the first line of the text file to be loaded into a table header cell (<th>) and the remainder of the file into an associated table data (<td>) cell.

I think i use an If statement, but havnt a clue what to do
Link to comment
Share on other sites

use first_element = array_shift ( $array_of_lines );l

example...

[code]<?
    $filename = 'text.txt';
    $array_of_lines = file ( $filename );
?>
<table>
<tr>
<th><?=array_shift ( $array_of_lines );?></th>
</tr>
<tr>
<?foreach ( $array_of_lines AS $item ):?>
<td><?=$item;?></td>
<?endforeach?>
</tr>
</table>[/code]

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