$file = fopen("test.txt","r");
while($line = fgets($file)) {
$line = trim($line);
list($model,$price) = preg_split('/\s+/',$line);
if(empty($price)) {
$price = 0;
}
$sql = "UPDATE products
SET products_price=$price
WHERE products_model='$model'";
// run the sql query.
}
fclose($file);
txt文件是这样的:代码含义是什么?
model price
LB2117 19.49
LB2381 25.99
1,什么是的list($model,$price) = preg_split('/\s+/',$line);
我知道preg_split
像explode
的意思,但我不知道what't上述线路的参数含义 2 ,如何跳过第一条记录。
但是当我运行的代码它显示了一个错误,请注意:未定义抵消: 1在第11行的D:\ www \ update.php中。第11行是列表($ model,$ price)= preg_split('/ \ s + /',$ line); – dreamchaser