0

I have a text document with a bunch of text and I want to grab each line in "allVersions" and store them to an array.

text document

bible.versions = {
// prebuild version array
versionData: null,

// versions by key
versionsByKey: {},

getVersion: function(key) {
    return this.versionsByKey[key];
},

allVersions: [
'ar_etr',
'ar_vady',
'el_tisch',
'en_kjv',
'en_wbtc',
'fr_s21',
'he_wlc'

],

loadingVersionIndex: -1,

loadingCallback: null,

loadNextVersion: function() {

php

$myarray = file_get_contents('file.js');

resulting array

$myarray = array('ar_etr', 'ar_vady', 'el_tisch', 'en_kjv', 'en_wbtc', 'fr_s21', 'he_wlc');

3 Answers 3

1

I think you are looking for the File function in PHP.

http://php.net/manual/en/function.file.php

This function reads an entire text file into an array, one line of text per array index.

Sign up to request clarification or add additional context in comments.

Comments

0
$myarray = explode('\n', file_get_contents("filename.txt"));

file_get_contents() returns a string containing the file, and explode(<delimiter>, <string>) splits the string into an array based on the delimeter.

But Matt's answer is better:

file("filename.txt")

Comments

0

If your file is supposed to be json then you can use json_decode():

$myarray = json_decode(file_get_contents('file.js'), TRUE);

The second argument of TRUE makes $myarray an array instead of an object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.