I am reading a file in, the file has the formatting of each paragraph on a line, and in some of the lines there is txt_field or cbox. Like:

This is a paragraph containg txt_field and cbox.

I am trying to replace cbox and txt_field with information I got from a submitting page, I have all the checkboxes sending, so I can put them back in orde, but for some reason my code willl not replace all of the cbox, I am using the same code I was with the txt_field, and it works fine. Here is my code, kind of long.

<?
$formfile=file("jus-purchase.txt");
$chars_line = 130;
$fontsize = 1.5;
$fontface = "Arial";
$txt_index = 0;
$cbindex = 0;

// Print Header
$header = file("header.txt");
for($index = 0; $index < count($header); $index++)
{
$txt_pos = strpos($header[$index], "txt_field");
while(is_int($txt_pos))
{
//Replace all txt_field with the replacement values
$header[$index] = substr_replace($header[$index], "$txtbox[$txt_index]", $txt_pos, 9);
$txt_index++;
$txt_pos = strpos($header[$index], "txt_field");
}
print("<FONT SIZE="$fontsize" face="$fontface">$header[$index]<BR></FONT>n");
}

echo "<TABLE>n";
for($index=1; $index < count($formfile); $index++)
{
$txt_pos = strpos($formfile[$index], "txt_field");
while(is_int($txt_pos))
{
$formfile[$index] = substr_replace($formfile[$index], "$txtbox[$txt_index]", $txt_pos, 9);
$txt_index++;
$txt_pos = strpos($formfile[$index], "txt_field");
}

$cbox_pos = strpos($formfile[$index], "cbox");

$index2 = $index + 1;
$stringlen=strlen($formfile[$index]);
if($stringlen > $chars_line)
{
$buffer[0] = substr_replace($formfile[$index], "|", $chars_line, 1);
$ex = explode ("|", $buffer[0]);
$spacepos = strrpos($ex[0], " ");
$buffer[0] = substr_replace($formfile[$index], "|", $spacepos, 1);
$ex = explode ("|", $buffer[0]);
$formfile[$index] = $ex[0];

if(strlen($formfile[$index2]) == 1)
{
$buffindex = $index2;
$buff_start = array_slice($formfile, 0, $buffindex);
$buff_end = array_slice($formfile, $buffindex);
$buff_start[] = " ";
$formfile = array_merge($buff_start, $buff_end);
}

$ex[1] .= "$formfile[$index2]";
$formfile[$index2] = $ex[1];

while(is_int($cbox_pos))
{
if($checkb[$cbindex] == "on")
{
$formfile[$index] = substr_replace($formfile[$index], "<INPUT TYPE="checkbox" CHECKED>", $cbox_pos, 4);
}
else
{
$formfile[$index] = substr_replace($formfile[$index], "<INPUT TYPE="checkbox">", $cbox_pos, 4);
}
$cbindex++;
$cbox_pos = strpos($formfile[$index], "cbox");
}


}

print("<TR><TD><FONT SIZE="$fontsize" face="$fontface">$index***</TD><TD><FONT SIZE="$fontsize" face="$fontface">$formfile[$index]</TD></TR>n");
}
echo "</TABLE>";
?>


[This message has been edited by Chris Pickett (edited July 10, 2000).]