Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Take form input in CSV and display results in a table using PHP

Status
Not open for further replies.

dreamaz

Technical User
Dec 18, 2002
184
CA
Greetings,

I would like to create a form, one field where I can paste data thats uses comma separated values and would like to have output displayed in a table or fields

here is a sample that I would paste into the form:

12/06/2005,15:41:08,172.16.255.110,Stop,1234567890@mike.com,200,1234567890@mike.com,172.10.55.10,36868,10.10.10.26,000001234567890,172.10.55.10,2,21965,57770,183,1,,,,,,,1133883668,,312400000B61,1c-3kjeX,1c-3kjeW,59

When i click submit i would like display similar to

DATE: 12/06/2005
TIME: 15:41:08
IP 1: 172.16.255.110
STAT: Stop
NUMBER: 1234567890@mike.com

Any help on how i could do this is appreciated. Its currently quite confusing to read the output in CSV all the time and I'm hoping to make this easier

Thanks,

dR
 
You would need to parse the CSV file server-side using various combinations of explode and string manipulation.

Show us your code to date and we can help you solve any specific problems you are having.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
Thanks Jeff,

Right now i just have a blank page with a form with a large text field (5 lines) with a submit button. There is no code yet as its the code I needed help with - I have never done this before.

I do have basic experience with PHP creating/updating records but thats about it.

Thanks

dR
 
OK I managed to get something basic working using the following:

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="feild1" cols="50" rows="5" id="feild1"></textarea>
<input type="submit" value="CONVERT!">
</p>
</form>
<?php if(isset($_POST['feild1'])){
$BREAK = explode(",", $_POST['feild1']);

ECHO $BREAK[0];
ECHO $BREAK[1]; and so on

Now what if I have multiple lines that need to be broken up? ie, the current setup only processes one line and breaks that up. I have multiple lines all separated which I would then like all displayed in an excel type format row by row. Can someone help?

Thanks

dR
 
You can use a for loop to do this if you like...
Code:
for ($loop = 0; $loop < count($BREAK); $loop++) echo $BREAK[$loop];

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
WORKED LIKE A CHARM!!

Thanks for your help Jeff!! Much Appreciated

dR
 
One more question on that ;)

Do I no longer have the arrays that were created from the explode? I was planning on using those to separate the values in a table format. So as it is right now, I have everything on one line without the commas (all joined together)

Thanks,

dR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top