|
Posted by news on 09/18/05 03:37
Geoff Berrow wrote:
> Try setting up a simple multidimensional array and echoing it to screen.
> Then add your checking function when you understand what's going on.
Is this not a "simple multidimensional array"? (Wouldn't surprise me if
it's not.
OK, here's all of it, plus a bit of code to show what's in the array.
Using that' I've tried to manipulate it to match the a with the b, but
it's all coming out as individual items.
That made no sense.
$a = array();
$a[0][0] = "Name";
$a[0][1] = $name;
$a[1][0] = "Message";
$a[1][1] = $msg;
$a[2][0] = "Subject";
$a[2][2] = $subject;
function valid_field($field,$value)
{
// return FALSE if it contains characters which
// which AREN'T on the specified list
if(ereg("[^[:space:]a-zA-Z0-9_.-\!\\'\,]{1,}", $value))
{
$funcerror = $field." value of: <span
class='bolding'>\"".$value."\"</span> contains invalid characters.<br
/>";
return $funcerror;
}
else
{
return true;
}
}
while (list ($x, $tmp) = each ($a)) {
while (list ($y, $val) = each ($tmp)) {
echo "$x, $y, $val<br />";
}
}
foreach ($a as $v1) {
$fieldname = $v1;
foreach ($v1 as $v2) {
$returned = valid_field($fieldname,$v2);
if ($returned != "true") {
$error .= $returned;
$errflag = "1";
}
}
}
The while loop puts out the following:
0, 0, Name
0, 1, Liam
1, 0, Message
1, 1, Hello, this is a test msg.
2, 0, Subject
2, 2, It's a test subject.
Navigation:
[Reply to this message]
|