you can code like:
$val="Veg
Tomato
Potato
Fruits
mango
banana";
$textAreaVal = $val;
$arrVal = explode(PHP_EOL, $textAreaVal);
for($i=0; $i < count($arrVal); $i++){
$type="";
$isInIf = false;
if($arrVal[i] == 'Veg'){
$type="Veg";
}else if($arrVal[i] == 'Fruits'){
$type="Fruits";
}
if($type != ''){
// your insert query here
// insert into tbl(type, name) values('$type', '$arrVal[i]')
}
}