1 回答
TA贡献1811条经验 获得超5个赞
你可以用正则表达式拆分它:
preg_match_all('/ ?([^\$]+)(\$[0-9\.,]+)(\$[0-9\.,]+)(\$[0-9\.,]+)/i',$str,$results);
该$results数组将包含索引 0 处的完整匹配项,后跟名称、小计、保留、总计:
[
[
"Liane Lanford$310.40$0.00$325.92",
" Ken Christenson$134.75$0.00$141.49",
" Melissa Jaramillo$951.78$0.00$999.37"
],
[
"Liane Lanford",
"Ken Christenson",
"Melissa Jaramillo"
],
[
"$310.40",
"$134.75",
"$951.78"
],
[
"$0.00",
"$0.00",
"$0.00"
],
[
"$325.92",
"$141.49",
"$999.37"
]
]
对于插入部分(您在评论中询问),试试这个:
试试这个:
for ($i=0;$i<count($array[0]);$i++) {
mysqli_query($link, "INSERT INTO table(name,subtotal,holdback,total) VALUES ('" . $array[0][$i] . "','" . $array[1][$i] . "','" . $array[2][$i] . "','" . $array[3][$i] . "') ");
}
但请记住,应该检查和转义这些值。如果任何名称包含 ' ,则查询将失败
- 1 回答
- 0 关注
- 98 浏览
添加回答
举报