One, read the file
First explain what is reading the file itself, what is called reading the file input. For example test.php inside the content <?php echo "test";?>
1, read the file itself is to read all the contents of the file, read it can get <?php echo "test";?>
2, read the file output is to read the contents of the file, read after the test
Second, fopen method
1, read the file itself
<?php
$filename = "test.php";
$handle = fopen ($filename, "R");
$contents = Fread ($handle, FileSize ($filename));
Fclose ($handle);
echo strlen ($contents);
?>
2, read the file output
<?php
$filename = "http://localhost/test/test.php";
$handle = fopen ($filename, "R");
$contents = "";
while (!feof ($handle)) {
$contents. = Fread ($handle, 8192);
}
Fclose ($handle);
echo strlen ($contents);
?>
The above two read files are the same one, but why is it different, http://localhost/test/test.php, where the test.php file is explained, fopen just get the script entered the content, see the PHP official website explain it
fopen () binds the name resource specified by filename to a stream. If filename is "scheme://..." Format, the Search protocol processor (also known as the Encapsulation Protocol) is treated as a url,php to handle this pattern. If the protocol has not yet registered the encapsulation protocol, PHP will issue a message to help check for potential problems in the script and continue with filename as a normal filename.
Three, the file method
1, read the file itself
<?php
$filename = "test.php";
$content = file ($filename); Get array
Print_r ($content);
?>
2, read the file display output
<?php
$filename = "http://localhost/test/test.php";
$content = file ($filename);
Print_r ($content);
?>
Four, file_get_contents method
1, read the file itself
<?php
$filename = "test.php";
$content = file_get_contents ($filename); Get string
echo strlen ($content);
?>
2, read the file display output
<?php
$filename = "http://localhost/test/test.php";
$content = file_get_contents ($filename);
echo strlen ($content);
?>
Five, ReadFile method
1, read the file itself
<?php
$filename = "test.php";
$num = ReadFile ($filename); Returns the number of bytes
Echo $num;
?>
2, read the file display output
<?php
$filename = "http://localhost/test/test.php";
$num = ReadFile ($filename); Returns the number of bytes
Echo $num;
?>
Vi. the Ob_get_contents method
1, read the file display output
<?php
Ob_start ();
Require_once (' bbb.php ');
$content = Ob_get_contents ();
Ob_end_clean ();
echo strlen ($content);
?>
Summarize
PHP, a lot of ways to read the file, read the URL method is also a lot of individuals summed up a bit, if there is no please correct me, if there is insufficient please add.