<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<title>String parser</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Vivian Lam" />
<style type="text/css">
pre { border: 1px solid #ccc; padding: 1em; }
td { border: 1px solid #ccc; padding: 0.5em; border-collapse: collapse; }
tr.alt { background: #eee; }
</style>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<p>Make it look something like this:</p>
<pre>
Name :: Anonymous
Food :: Pineapples
Drink :: Caesar's
Movie :: Labyrinth
Email :: hottie293874@hotmail.com
David Bowie? :: Yes
</pre>
<p><textarea name="stuff" rows="5" cols="" style="width:50%;"></textarea></p>
<p><input type="submit" value="FIRE AWAY"></input></p>
</form>
<?php
if($_POST) { // Do this only if some data has been submitted
echo "<p>You made a table!</p>\n";
echo "<table>\n";
$color = false; // Alternates so that every other row is styled differently
$lines = explode("\n", htmlspecialchars($_POST['stuff'])); // Split text in to array, so each line of text is an entry in the array
foreach($lines as $line) {
$x = explode("::", $line); // Split line in to two, separated by the ::
if($color) {
echo "<tr>";
$color = false;
} else {
echo "<tr class='alt'>";
$color = true;
}
echo "<td>".trim($x[0])."</td><td>".trim($x[1])."</td></tr>\n"; // Display as a table
}
echo "</table>";
}
?>
</body>
</html>