Jump to content

Recommended Posts

I need a function to search a text file for the value entered into the form and display the name (in this case name of the bank) of the value under form field.

 

I am trying to validate a ach bank routing number entered by a user in a text field.  I have a text file with all of the routing numbers and names of all of the banks in the country.  They are in this format:

 

011075202O0110000151101802000000000SOVEREIGN BANK                      1125 BERKSHIRE BLVD.                WYOMISSING          PA196100000877768226511     

011100012O0110000151072805000000000BANK OF AMERICA N.A.                PO BOX 27025                        RICHMOND            VA232617025800446013511   

 

The first 9 digits of each entry is the routing number. 

 

Can anyone point me in the right direction?

Link to comment
https://forums.phpfreaks.com/topic/126466-function-to-search-text-file/
Share on other sites

Look at the php manual, and see:

 

  • The fopen() function
  • The fread() function
  • and then you will need something like preg_match() with a regular expression

 

Thr regular expression looks like it should be easy, because the number of numbers in a row will exceed 9

Do something like...

 

$contents = file('myfile.txt');
foreach($contents as $line) {
if(substr($line, 0, 9) == $_GET['routeNum']) {
	// The line with the shipping number was found, line held in $line
}
}

 

I don't quite understand what you want to do once you find the line so I didn't include that, but that's how you can find it.

Do something like...

 

$contents = file('myfile.txt');
foreach($contents as $line) {
if(substr($line, 0, 9) == $_GET['routeNum']) {
	// The line with the shipping number was found, line held in $line
}
}

 

I don't quite understand what you want to do once you find the line so I didn't include that, but that's how you can find it.

 

What I need it to do is when the user enters the routing number into the text field the function compares it automatically when the user goes to the next text field.

 

So if I have a form that looks like:

 

 

Name: Bob Smith

 

Bank Routing Number:011100012

                            BANK OF AMERICA N.A (display bank name from file matching routing number entered, if not found display "error routing number invalid".  One or the other displayed automatically when user tabs or clicks on next field)

 

Bank Acct Number:1234567

 

Payment Amount:100.00

 

 

 

The file comes from the Federal Reserve and this is the only format and is located at https://www.fededirectory.frb.org/FedACHdir.txt

 

Thanks for the start I will see if I can figure it out some more.

 

Tom

In PHP your code will compare routing numbers on the server side after the post is completed.  If this is what you are requesting then just read the entire file into memory and do a strpos() to get what you are looking for. 

 

Otherwise to me it sounds like you are looking either for an AJAX/RPC "realtime" comparison which would require just a pure javascript (client-side) check in addition to the the PHP server side.

 

However the fact that you don't understand these two principals and you are working with a finical transaction of some sort would beg the question about how secure your code will ultimately be, and do you or your client feel comfortable with that?

You are correct that I do need a real time comparison and have also looking into a javascript solution used in concert with php payment form I already have.  I do understand the two principles of server side versus client side.  This is going to be used as an extension for billing software already in place.  I am learning all I can so eventually I can code what I need.  Any code that is put into production is encrypted and so is the data itself.  Security is a top priority-has to be these days.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.