tags:

views:

24

answers:

1

I have a client that wants to be able to copy a range of cells from excel and paste it into a web browser. It will basically be the code of a product in one column and a price in another column. I want to be able to submit this as a form to do some php form processing on it. Is there a way that this can be accomplished? He wants to copy and paste instead of modifying prices in a form format.

+1  A: 

When the data is pasted it will tab delimited. You can either just have him paste the text into a textarea then submit the form where you process it. Or you can get fancy and have some javascript parse the data when the textarea changes. I'd start simple and go for option 1

if ( !empty( $_POST ) ) {

    list( $code, $price ) = explode( "\t", trim( $_POST['data'] ) );
    // do somethign with code and price

}

EDIT:

To allow for multiple lines use explode( "\n", $_POST['data'] ); Then you can loop through the array and get individual lines.

Galen
You will also need to account for multiple lines.
cdburgess
Probably be safer to use `str_getcsv()` and let it handle the parseing/splitting for you. You'd still have to split into individual lines, though.
Marc B