Page 1 of 1

Separating Raw Text into Tables

Posted: Tue Jul 08, 2003 10:00 pm
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?

Posted: Tue Jul 08, 2003 10:47 pm
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>

Posted: Wed Jul 09, 2003 9:12 am
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>';
?>