在textarea中逐行使用PHP读取单词并插入mySQL

时间:2015-11-19 07:05:13

标签: php mysql insert textarea readline

  1. 我需要读取逐行插入textarea的数据
  2. 然后需要搜索某些单词(例如Fruit)
  3. 一旦找到该单词,从下一行开始逐行向DB插入,直到找到一个新的空行(Apple Mango Orange)
  4. sample screen attached

1 个答案:

答案 0 :(得分:-1)

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]')
    }
}