///////////////////////////////////////////////////////////////////////////////////////////////
#1. Open a connection to a file, using fopen(), and work with that file line by line
if ($fh = fopen('A1_data_input/data_input_css/footer.txt', 'r')) {
while (!feof($fh)) {
$lineA = fgets($fh);
echo "lineA: $lineA
";
}
fclose($fh);
}
echo "
";
OUTPUT:
lineA: cursive
lineA: 20pt
lineA: red
///////////////////////////////////////////////////////////////////////////////////////////////
#2. Read the entire file into a string using file_get_contents
$file = file_get_contents('A1_data_input/data_input_css/footer.txt');
echo $file;
echo "
";
OUTPUT: cursive 20pt red
///////////////////////////////////////////////////////////////////////////////////////////////
#3. Read the entire file into an array of lines using file.
$file_lines = file('A1_data_input/data_input_css/footer.txt');
foreach ($file_lines as $lineB) {
echo $lineB;
}
echo "
";
OUTPUT: cursive 20pt red
///////////////////////////////////////////////////////////////////////////////////////////////
#4.
$lines = file('A1_data_input/data_input_css/footer.txt');
foreach ($lines as $line_num => $lineC) {
echo "Line #{$line_num} : " . htmlspecialchars($lineC) . "
\n";
}
echo "
";
OUTPUT:
Line #0 : cursive
Line #1 : 20pt
Line #2 : red
///////////////////////////////////////////////////////////////////////////////////////////////
.