我需要用php捕获/分离一些特定的数据值。似乎在php中就像preg_match()一样。但没有成功。我将展示我正在工作的一小部分数据。原始文件有超过32万个字母。
129/09/20031820252310112414060213090516030,005BA15446454880725759349.765,82689,8410,004,002,000,000,000,00PRSPSPSP206/10/20032315050412162006111924010913070,001SP184623281252478188596.323,701.388,9510,004,002,000,000,000,00313/10/20032023120806010711140416100917240,002SP158689796244608211400.623,702.173,3610,004,002,000,000,000,00SP420/10/20031605252423081202171801100419130,001MT2589569123912706657902.226,021.498,7210,004,002,000,000,000,00527/10/20031513200211240916042325120819010,002BA47214736195636860992380.017,55687,4910,004,002,000,000,000,00MS603/11/20032319010507211610152506021204170,002RJ39314242162320888301489.140,061.066,8310,004,002,000,000,000,00RS
我需要将这些数据分开,就像那样。可以是数组,也可以是.txt文件。
29/09/2003182025231011241406021309051603,
06/10/2003231505041216200611192401091307,
13/10/2003202312080601071114041610091724,
20/10/2003160525242308120217180110041913,
27/10/2003151320021124091604232512081901,
03/11/2003231901050721161015250602120417,
这些数据有一种获取价值的模式。值/ 20将是关键,因此他可以选择循环值,因为它是此数据的默认值。
如果preg_match()已经工作,它将采用基于值/ 20的值,将使用substr()正数和负数来选择选择找到的每个值的范围,以便在找到此数量之后在数组或.txt文件上播放。我已经尝试过array_search(),但它似乎带来了bolean响应(TRUE或FALSE)。我也尝试使用explode,但是值/ 20消失了,因此丢失了要搜索的回车键。
我真的迷路了,我正在寻找好几天,并认为有人可以给我一条问题的路径。是否有一些其他命令在PHP中帮助我解决这个问题?
答案 0 :(得分:3)
希望这有助于你
$exp = "/[\\d]{2}[\\/][\\d]{2}[\\/](.*?),/";
$data = "129/09/20031820252310112414060213090516030,005BA15446454880725759349.765,82689,8410,004,002,000,000,000,00PRSPSPSP206/10/20032315050412162006111924010913070,001SP184623281252478188596.323,701.388,9510,004,002,000,000,000,00313/10/20032023120806010711140416100917240,002SP158689796244608211400.623,702.173,3610,004,002,000,000,000,00SP420/10/20031605252423081202171801100419130,001MT2589569123912706657902.226,021.498,7210,004,002,000,000,000,00527/10/20031513200211240916042325120819010,002BA47214736195636860992380.017,55687,4910,004,002,000,000,000,00MS603/11/20032319010507211610152506021204170,002RJ39314242162320888301489.140,061.066,8310,004,002,000,000,000,00RS\n";
preg_match_all($exp, $data, $result);
print_r($result);
输出:
Array
(
[0] => Array
(
[0] => 29/09/20031820252310112414060213090516030,
[1] => 06/10/20032315050412162006111924010913070,
[2] => 13/10/20032023120806010711140416100917240,
[3] => 20/10/20031605252423081202171801100419130,
[4] => 27/10/20031513200211240916042325120819010,
[5] => 03/11/20032319010507211610152506021204170,
)
[1] => Array
(
[0] => 20031820252310112414060213090516030
[1] => 20032315050412162006111924010913070
[2] => 20032023120806010711140416100917240
[3] => 20031605252423081202171801100419130
[4] => 20031513200211240916042325120819010
[5] => 20032319010507211610152506021204170
)
)