×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

PHP - > Upload process and create a new csv file

PHP - > Upload process and create a new csv file

PHP - > Upload process and create a new csv file

(OP)
Hello, i have an csv document with 2 columns that have the following example data:-

REF OEM
987392405 DSB52402402404240 / LR2401240574 / SOB52402402404240 / SOB524024024042
987246240 1240240196240 / 1H240615423A / 1H240615423B / 1H240615423D / 1H240615423DX / 6K240615423B / 1G240615423 / 7M240615423
etc...

In a php page, i want to select a csv file, process it and then create a new csv file which has been processed to look like the following?

REF OEM
987392405 DSB52402402404240
987392405 LR2401240574
987392405 SOB52402402404240
987392405 SOB524024024042

Please can anyone show me how to do it?

many thanks

BF

RE: PHP - > Upload process and create a new csv file

Hi

Personally I would do it like this :

CODE --> command line

master # php -R 'if($argi==1)echo"$argn\n";else{$p=explode("\t",$argn,2);foreach(explode(" / ",$p[1])as$o)echo"$p[0]\t$o\n";}' < Brianfree.csv
REF             OEM
987392405       DSB52402402404240
987392405       LR2401240574
987392405       SOB52402402404240
987392405       SOB524024024042
987246240       1240240196240
987246240       1H240615423A
987246240       1H240615423B
987246240       1H240615423D
987246240       1H240615423DX
987246240       6K240615423B
987246240       1G240615423
987246240       7M240615423 
Assuming that the column separator is always a tab and the OEM's internal separator is always space+slash+space. Some error checking may help though.

If need help adapting it to your context, let us know. ( And please post preformatted text between [pre] and [/pre] TGL tags. )

Feherke.
feherke.github.io

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close