我已将路由号码映射到银行名称,但有一个问题:我无法弄清楚如何只获取银行名称,不银行名称+地址的一部分。我意识到我已设置substr()
以获得35个字符,但我不知道它会忽略空格并用字符串中的下一个字符填充35长度要求(在本例中为地址)。
我错过了一些明显的东西吗?我应该不使用substr()
吗?
//routing number, position: 0-9
//bank name, position: 35-70
$str="011000015O0110000150020802000000000FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E. ATLANTA GA303094470866234568111
011000028O0110000151072811000000000STATE STREET BANK AND TRUST COMPANY JAB2NW N. QUINCY MA021710000617664240011
011000138O0110000151101310000000000BANK OF AMERICA, N.A. 8001 VILLA PARK DRIVE HENRICO VA232280000800446013511
011000206O0110000151072505000000000BANK OF AMERICA N.A PO BOX 27025 RICHMOND VA232617025800446013511
011000390O0110000151072505000000000BANK OF AMERICA N.A PO BOX 27025 RICHMOND VA232617025800446013511 ";
$arr=str_split($str, 157);
echo '<br>';
echo 'routing:'.substr($arr[0], 0, 9);
echo 'name:'.substr($arr[0], 35, 70);
echo '<br>';
echo 'routing:'.substr($arr[1], 0, 9);
echo 'name:'.substr($arr[1], 35, 70);
echo '<br>';
echo 'routing:'.substr($arr[2], 0, 9);
echo 'name:'.substr($arr[2], 35, 70);
echo '<br>';
echo 'routing:'.substr($arr[3], 0, 9);
echo 'name:'.substr($arr[3], 35, 70);
结果:
routing:011000015name:FEDERAL RESERVE BANK 1000 PEACHTREE ST N.E.
routing:011000028name:STATE STREET BANK AND TRUST COMPANY JAB2NW
routing:011000138name:BANK OF AMERICA, N.A. 8001 VILLA PARK DRIVE
routing:011000206name:BANK OF AMERICA N.A PO BOX 27025
答案 0 :(得分:0)
好的,我是个白痴,我误解了substr()
是如何运作的。
长度参数应为35
而不是70
。我的大脑正在考虑范围。
所以这个:
echo 'name:'.substr($arr[2], 35, 35);
而不是这个:
echo 'name:'.substr($arr[2], 35, 70);