0

我已经将路由号码映射到银行名称,但存在一个问题:我无法弄清楚如何仅获取银行名称而不是银行名称 + 其地址的一部分。我意识到我已经设置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
4

1 回答 1

0

好吧,我是个白痴,我误解了它的substr()工作原理。

长度参数应该是35而不是70。我的大脑在思考一个范围。

所以这:

echo 'name:'.substr($arr[2], 35, 35);

而不是这个:

echo 'name:'.substr($arr[2], 35, 70);
于 2013-09-17T14:19:53.040 回答