I'm writing a PHP script which stores the values in the file in an array. I want newlines and spaces to be preserved.
The text file looks like below:
abc
pqr
xyz
What I thought is to use cat
Linux command to read the file and then direct it's value in an array.
This is what I tried:
$input = '/var/www/oj/1.in';
$array = system(cat $input);
That didn't work. Any ideas?
Try the function that is used for this:
$array = file($input);
print_r($array);
But since you don't actually want an array as stated in the question, try:
$output = file_get_contents($input);
Or to skip the empty lines:
$output = implode(file($input, FILE_SKIP_EMPTY_LINES));