I have an assignment that asks me to retrieve delimited text from form values. The text is delimited with an asterisk (*). I have been trying to use the explode() function to do this, but I’m not having any luck. Here is my code:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Bills</title>
<style>
body {
font-family:Verdana, Geneva, sans-serif;
}
.bad {
color:#FF0000;
}
</style>
</head>
<body>
<h1>My Bills</h1>
<?php
echo "
<p><strong>Sort Order for Items:</strong>
<form method='post'>";
$choice = $_POST['sort'];
if ($choice == 'ascending')
echo "
<label for='ascending'>Ascending</label><input name='sort' type='radio' id='ascending' value='ascending' checked='checked' />
<label for='descending'>Descending</label><input name='sort' type='radio' value='descending' id='descending' />";
if ($choice == 'descending')
echo "
<label for='ascending'>Ascending</label><input name='sort' type='radio' id='ascending' value='ascending' />
<label for='descending'>Descending</label><input name='sort' type='radio' value='descending' id='descending' checked='checked' />";
if ($choice == '')
echo "
<label for='ascending'>Ascending</label><input name='sort' type='radio' id='ascending' value='ascending' checked='checked' />
<label for='descending'>Descending</label><input name='sort' type='radio' value='descending' id='descending' />";
echo "
<table border='0' cellpadding='3' cellspacing='5'>
<tr>
<td><h4>Item</h4></td>
<td><h4>Amount</h4></td>
</tr>
";
for($row=1; $row<5;$row++)
{
$item_name='item_name'.$row;
$item_value = $_POST[$item_name];
$amount_name='amount_name'.$row;
$amount_value = $_POST[$amount_name];
$myelement = "$item_value*$amount_value*";
$myarray = array($myelement);
array_push($myarray, $myelement); //Adds $myelement to the end of the $myarray array
foreach ($myarray as $myName)
{
$list = explode("*", $myName);
echo "<br>".$list[0];
}
echo
"<tr>
<td><input type='text' name='$item_name' value='$item_value' /></td>
<td><input type='text' name='$amount_name' value='$amount_value' /></td>
";
if (!empty($amount_value))
{
if(is_numeric($amount_value))
{
$total = $total + $amount_value;
}
else {
echo
"<td class='bad'>Amount Invalid: $amount_value</td>";
$error_count++;
}
}
echo"
</tr>
";
}
echo "
<tr>
<td colspan='2'>
<input name='' type='submit' value='Submit' />
</td>
</table>
";
if ($error_count > 0)
{
echo "<br /><span class='bad' />Errors: $error_count</span>";
}
else
{
echo "<br />Total: $total";
}
?>
</form>
</body>
</html>
I don’t know what your crazy code do, but this is proper syntax:
or
See http://php.net/manual/en/function.list.php
And i suppose you should change
$sort_line[$array_counter]to$myName