I need to include file in array

Viewed 22

I tried to include the php file in array like that but it is not working username.php file is : "mohammed", "ahmed", "hafian", "gimmy", "osama" and the main file is : $usernames = array(include 'usernames.php');

2 Answers

You will need to open and read the file, you can't just include and expect it to parse the file and store into your array. Also, can you make usernames.php a text file and not PHP code? You don't want to be parsing PHP code. I think you'll need to approach it like this:

`<?php
  $fn = fopen("usernames.txt","r");

  while(! feof($fn))  {
     $result = fgets($fn);
     # parse line and append to array
  }

  fclose($fn);
?>`
Related