// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('my_file.txt');
$myvar = "b";
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
if($myvar = htmlspecialchars($line)."<br \>\n"){
// echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
//echo $myvar." "."matches ".htmlspecialchars($line)."<br \>\n";
echo trim($myvar." "."matches ".htmlspecialchars($line)."<br />\n");
}else{
//echo $myvar." doesn't match ".htmlspecialchars($line)."<br />\n";
}
}
// Another example, let's get a web page into a string. See also file_get_contents().
$html = implode('', file('my_file.txt'));
// Using the optional flags parameter since PHP 5
$trimmed = file('my_file.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
my_file.txt:
