$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