请我需要帮助,我正在从php导入csv数据,我需要删除以下字符">"从CSV中的股票行导入。(php中的数量数组)
CSV ROW stock - check here
// MAIN CYCLE
$row_num = 0;
if (($handle = fopen($remote_csv_file, "r")) !== false) {
while (($data = fgetcsv($handle, 100000, ";")) !== false) {
$row_num++;
if ($row_num == 1) {
// SKIP FIRST LINE (HEADER)
continue;
}
//quantity = EAN --> STOCK
if ($data[2] == '' || !is_numeric($data[3])) {
// SKIP EMPTY VALUES
continue;
}
//price = EAN --> PRICE
if ($data[2] == '' || !is_numeric($data[1])) {
// SKIP EMPTY VALUES
continue;
}
//price bezna = EAN --> PRICE W
if ($data[2] == '' || !is_numeric($data[0])) {
// SKIP EMPTY VALUES
continue;
}
// INPUT SANITIZATION
$ean13 = trim($data[2]);
$quantity = ($data[3] >= 0) ? $data[3] : 0; // need to remove ">" character from CSV row "instock" when importing data
$price = ($data[1] >= 0) ? $data[1] : 0; //
$price_wholesale = ($data[0] >= 0) ? $data[0] : 0; //
谢谢你的帮助
一个简单的trim()
应该为您使用空格和大于号作为字符来删除
trim($data[3], ' >');
例子$data = ['a','b', 'c', ' > 12 '];
echo trim($data[3], ' >');
结果
12