|
|
||||

Imagine we have a text file called vars.txt. Inside vars.txt we have tab delimited data which we want to access and read into variables.
First let's look at our vars.txt file. In it are 3 strings separated by tabs. You can't see them when you open the file in your browser. But they appear to 'the computer' as \t for tabs.
Now let's open vars.txt and read all the contents into one variable.
$PATH = $_ENV['DOCUMENT_ROOT']; #get server path to webshare (more info)
$file=$PATH.'/my_dir/vars.txt';
$data = fread(fopen($file, "r"), filesize($file)); # use fread, open for reading, how much? full size of $file.
$data_split = split("\t", $data); #break up the data into $data_split array, split where the tabs are
#assign the first item of $data_split to $fname, etc
$fname=$data_split[0];
$lname=$data_split[1];
$age=$data_split[2];
#now print for viewing:
echo ("Filepath was $file<br>\n");
echo ("Name is $fname $lname, age is $age");