[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

output 2 files with info from one

Hi experts,

I  have a file.txt with firstname and lastname (delimited by space) info and need to output into 2 files, firstname.txt and lastname.txt

Thanks
0
gloriaewold41
Asked:
gloriaewold41
  • 4
  • 3
2 Solutions
 
gr8gonzoConsultantCommented:
<?php
$bothnames = file("file.txt");
foreach($line in $bothnames)
{
  $pieces = explode(" ",trim($line));
  file_put_contents("firstname.txt",$pieces[0]."\n",FILE_APPEND);
  file_put_contents("lastname.txt",$pieces[1]."\n",FILE_APPEND);
}
?>
0
 
gloriaewold41Author Commented:
It doesn't work, i've tried creating the files manually, thought it would just write them, but it didn't.
0
 
gr8gonzoConsultantCommented:
Does it give you any errors, or what is the result?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
gloriaewold41Author Commented:
No errors, blank page.
0
 
gloriaewold41Author Commented:
Anyone?
0
 
gr8gonzoConsultantCommented:
Sorry - I have been programming in another language recently and my brain mixed up syntax:

foreach($line in $bothnames)

should be:

foreach($bothnames as $line)
0
 
gloriaewold41Author Commented:
Now it works. Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now