0
$allMessages = array();
if ($file = fopen("messages.txt", "r")) {
    while(!feof($file)) {
        $line = fgets($file);
        $parts = explode(", ", $text);
        array_push($allMessages, $parts);
    }
    fclose($file);
}

echo '<pre>';
print_r($allMessages);
echo '</pre>';

i did this but it returned an empty string idk what happened

##returned Array ( [0] => Array ( [0] => )

[1] => Array
    (
        [0] => 
    )

[2] => Array
    (
        [0] => 
    )

[3] => Array
    (
        [0] => 
    )

[4] => Array
    (
        [0] => 
    )

) btw the file consist of names, message (it is separated by comma) it splits it by the explode function but it returned empty string pls help meh

Jerome Palayoor
  • 31
  • 1
  • 1
  • 9
  • `$text` is __defined nowhere__ – u_mulder Oct 23 '20 at 09:05
  • Well I was going to say let's turn IDK into I Do Know by using a var_dump($line) after you assign it in the while loop but then saw the next line where you are using $text and I Dont Know where that is assigned? It looks like a little typo there. – TimBrownlaw Oct 23 '20 at 09:06
  • possible duplicate of : [Read comma separated values from a text file using php](https://stackoverflow.com/questions/32962359/read-comma-separated-values-from-a-text-file-using-php) – Alive to die - Anant Oct 23 '20 at 09:07
  • But do you know 100% that each line is structured as xxxxx, yyyyyy with a comma space? – TimBrownlaw Oct 23 '20 at 09:07

1 Answers1

2

Seems to me that you want to do $parts = explode(", ", $line); because $text is not defined.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Henrik Erstad
  • 681
  • 3
  • 11
  • 21