So the 1. 2. 3. 4. are the lot numbers, and each item is on a single line...
Well, I'd first take the $_POST['textfield'] variable and explode it into an array of lines:
$items =explode("\n", $_POST['textfield']);
Now that I've got that, I just need to find the lot number and the description text. Regexps look like the best bet for this job.
foreach($items as $item)
{
if(preg_match('/^\s*(\d+)\.\s+(\S*)\s*$/', $item, $match))
{
Which, if you're not familiar with Perl-style regexps looks like a bunch of swearing:
/ # Start of the regexp
^ # Start of the $item line
\s* # Some possible whitespace
(\d+) # Some digits (which we collect for our lot number)
\. # A '.' (with a backslash, because . has a special meaning in regexps)
\s+ # Some whitespace
(\S*) # Some possible nonwhitespace (our lot description)
\s* # Some possible whitespace (it could happen...)
$ # The end of the $item line
/ # The end of the regexp
Now assuming that the line succesfully matched the pattern, we can put them in an array (for the moment):
$itemarray[$match[1]]=$match[2];
}
}
$match[1] contains the first bit of the regexp we collected (the lot number), likewise $match[2] contains the description. So now we've got an array of lot descriptions indexed by lot number. It's a fairly simple matter to get this into the database - there are things to watch out for like " characters in the descriptions, but what exactly these are tend to be fairly sensitive to your particular configuration.