我正在尝试将来自文本区域的数据加载分割为多个数组。
过程是:
面食数据到textarea
将textarea发布到insert.php
带逗号的Preg_replace标签
用逗号分解
print_r
使用的日期样本是:
Dr S Findlay 1234567890 Mickey Mouse 01/01/2001 Elective Waiting 02/02/2002 00:00 Dr one Day Case 03/03/2003 00:00 On Medical Advice Usual Place of Residence
我得到的结果是:
Array ( [0] => Dr S Findlay [1] => 1234567890 [2] => Mickey [3] => Mouse [4] => 01/01/2001 [5] => Elective Waiting [6] => 02/02/2002 00:00 [7] => Dr one [8] => Day Case [9] => 03/03/2003 00:00 [10] => On Medical Advice [11] => Usual Place of Residence [12] => )
这很好用,完全插入到mysql数据库中。但是,当我使用完整数据范围(可以是2x到50x)时,上面显示的数据量显示不同:
更真实的数据样本:
Dr S Findlay 1234567890 Mickey Mouse 01/01/2001 Elective Waiting 02/02/2002 00:00 Dr one Day Case 03/03/2003 00:00 On Medical Advice Usual Place of Residence
Dr Peter 1234557890 Mickey1 Mouse1 01/01/2003 Waiting 02/02/2014 00:00 Dr one Waiting Case
Dr Nail 1234569990 Mickey2 Mouse2 01/01/2009 Emergencey 02/02/2018 00:00 Dr one Emergencey 29/05/2018
结果:
Array ( [0] => Dr S Findlay [1] => 1234567890 [2] => Mickey [3] => Mouse [4] => 01/01/2001 [5] => Elective Waiting [6] => 02/02/2002 00:00 [7] => Dr one [8] => Day Case [9] => 03/03/2003 00:00 [10] => On Medical Advice [11] => Usual Place of Residence [12] => Dr Peter [13] => 1234557890 [14] => Mickey1 [15] => Mouse1 [16] => 01/01/2003 [17] => Waiting [18] => 02/02/2014 00:00 [19] => Dr one [20] => Waiting Case [21] => [22] => [23] => [24] => Dr Nail [25] => 1234569990 [26] => Mickey2 [27] => Mouse2 [28] => 01/01/2009 [29] => Emergencey [30] => 02/02/2018 00:00 [31] => Dr one [32] => Emergencey [33] => [34] => [35] => [36] => 29/05/2018 )
我想做什么(但无法弄清楚怎么做)将其拆分为数组,以便每行数据(13列并不总是包含数据)显示如下,以便我可以将所有数据插入到mysql中一气呵成。我不确定这是否有效,所以如果不能,请纠正我。
我希望它看起来像:
Array ( [0] => Dr S Findlay [1] => 1234567890 [2] => Mickey [3] => Mouse [4] => 01/01/2001 [5] => Elective Waiting [6] => 02/02/2002 00:00 [7] => Dr one [8] => Day Case [9] => 03/03/2003 00:00 [10] => On Medical Advice [11] => Usual Place of Residence [12] => )
Array ( [0] => Dr Peter [1] => 1234557890 [2] => Mickey1 [3] => Mouse1 [4] => 01/01/2003 [5] => Waiting [6] => 02/02/2014 00:00 [7] => Dr one [8] => Waiting Case [9] => [10] => [11] => [12] => )
Array ( [0] => Dr Nail [1] => 1234569990 [2] => Mickey2 [3] => Mouse2 [4] => 01/01/2009 [5] => Emergencey [6] => 02/02/2018 00:00 [7] => Dr one [8] => Emergencey [9] => [10] => [11] => [12] => 29/05/2018 )
正如我假设我可以给数组的每个部分命名$forename = $area[2] ;
然后用它来插入我数据库的正确字段?
对不起,如果这没有意义 - 或者如果我正在咆哮错误的树。所有&任何建议,帮助或信息表示赞赏。谢谢AJ
答案 0 :(得分:0)
你好兄弟你的解释很混乱但是和你一样 在此基础上描述了工作流程 想建议你下面的代码。试一试。
不确定会工作,但值得尝试
<?php
// explode by tab
$tabbedContent = 'Dr S Findlay 1234567890 Mickey Mouse 01/01/2001 Elective Waiting 02/02/2002 00:00 Dr one Day Case 03/03/2003 00:00 On Medical Advice Usual Place of Residence';
echo '<pre>';
var_dump(explode("\t", $tabbedContent));
echo '</pre>';
?>
至少这可能会缩短您的流程。