我打算从一个文件名中提取排序代码和账号,假设前6个数字代表排序代码,后8个数字代表账号。文件名的示例如下:
./uploads/Santander/Statement_01020387654321.qif我所写的似乎不起作用,因为我是新的正则表达式,也许有人可以解释这应该如何做,或者我哪里出了错。
$sort = '';
$acno = '';
$ret = preg_match('/Statment_[0-9]{14}\.(csv|qif|qfx|ofx)$/', $file);
if ($ret)
{
if (ereg ('/_[0-9]{14}\./', $file, $regs))
{
$reg = $regs[count($regs)-1];
$sort = substr($reg, 1, 6);
$acno = substr($reg, 7, 8);
}
}发布于 2011-03-07 19:37:02
已测试
echo $file ='./uploads/Santander/Statement_01020387654321.qif';
$ret = preg_match('/Statement_(\d{6})(\d{8})\.(csv|qif|qfx|ofx)$/', $file, $matches);
echo "<pre>";
print_r($matches);
returns
Array
(
[0] => Statement_01020387654321.qif
[1] => 010203
[2] => 87654321
[3] => qif
)发布于 2011-03-07 19:27:57
我相信精通正则表达式的人可以帮助你,但也有可能没有。从长远来看,它可能是更有吸引力的选择,因为它更容易维护。
$path = "./uploads/Santander/Statement_01020387654321.qif"
$filename = pathinfo($path, PATHINFO_BASENAME); // "Statement_01020387654321.qif"
$temp_array = explode("_", $filename);
$sortcode = substr($temp_array[1], 0, 6); // 010203
$account = substr($temp_array[1], 6, 8); // 7654321发布于 2011-03-07 19:29:26
在匹配的第一步中这样做:
$ret = preg_match('/Statement_([0-9]{6})([0-9]{8})\.(csv|qif|qfx|ofx)$/', $file, $matches);在$matches中,你有关于分拣号、账号和分机的信息。
https://stackoverflow.com/questions/5219064
复制相似问题