Separating Raw Text into Tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Caped Knight
Forum Commoner
Posts: 33
Joined: Wed Jan 01, 2003 6:20 pm
Location: Somewhere...out there...

Separating Raw Text into Tables

Post by Caped Knight »

I'm sure there's a way to do this, but I'm lost.

Let's say, for example, I wanted to separate this text into a table...

George Bob Joe
Joe George Bob

...so that each name goes into a separate <td> after it goes through a form submission. Of course, the data will be completely random so I can't use ereg_replace.

Any ideas?
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

something like this

Code: Select all

<?
$text = "George Bob Joe Joe George Bob";
$array = explode(" ", $text);
?>
<table>
    <tr> <?
        for($i = 0; $i < count($array); $i++) {
            echo "<td>". $array[$i] ."</td>";
        } ?>
    </tr>
</table>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Or:

Code: Select all

<?php
$text = 'George Bob Joe Joe George Bob'; 
$array = explode(' ', $text); 

echo '<table><tr>'; 

foreach($array as $value) {
 
    echo '<td>' . $value . '</td>'; 
} 

echo '</tr></table>';
?>
Post Reply