Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:37:47+00:00 2026-05-23T23:37:47+00:00

I am needing to turn a textfile into an array…I am not sure how

  • 0

I am needing to turn a textfile into an array…I am not sure how to go about this because the other features ive seen for php take an entire file and put it into an array but not quite how I want it to be so I am looking for advice here..
The following is written in a textfile:
“jim kroi,richard wuu,yan kebler,justin persaud”

How can I use php to make an array where automatically a loop puts each name as an item of the array until all the names run out?

so the end result of what I am trying to do is:
$array= array(“jim kroi”,”richard wuu”,”Yan kebler”,”justin persaud”);

So a loop of some sort would basically search upto each comma and extract the name before it until all of the names run out….

There are some php substr and such functions but I cant quite think of how to do this..

Yes, I do have code, here it is:

<?php
error_reporting(-1);




$fp = fopen('numbers.csv', 'w');

fputcsv($fp, $_POST['names']); 
fputcsv($fp, $_POST['numbers']); 


fclose($fp);



?>

i put them all in a csv but now how can I make 2 arrays, one with name the other with numbers? http://imageshack.us/photo/my-images/215/csv.png/

using implode I get the error:

Warning: implode() [function.implode]: Bad arguments. in C:\Program Files\xampp\htdocs\xampp\something.php on line 14

<?php
error_reporting(-1);

$myFile = "testFile.txt";


$fh = fopen($myFile, 'r'); // open file
$theData = fread($fh, 5); // read file and store in var
$array = explode("\n", $theData); // explode string by lines using \n
echo implode("<br/>", $theData); // put the array back together and show each item as a line
fclose($fh);


?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:37:47+00:00Added an answer on May 23, 2026 at 11:37 pm

    Something like:

    $names = array_map('trim', explode(',', file_get_contents('%yourFileHere')));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm needing to cache some data using System.Web.Caching.Cache . Not sure if it matters,
I'm needing to check the differences between two XMLs but not blindly, Given that
I'm needing to make this layout editor that uses a good bit of jQuery
I saw something about needing to have the assembly available for the type of
A client of mine is needing their current website to tie into an online
I'm needing to do something full-screen app, which would usually not be the problem.
I'm needing to delete a value in Isolated storage from javascript code. If this
I'm needing to prepare a date for insertion into MongoDB based on user input
In a desktop application needing some serious re-factoring, I have several chunks of code
I find myself needing to store public key certificates, and a single private key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.