file_get_contents php filesystem function example - reads a file and returns as string
file-get-contents-php-filesystem-function-example.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>file_get_contents php filesystem function example - reads a file and returns as string</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="file_get_contents php filesystem function example - reads a file and returns as string">
<meta name="keywords" content="php, example, code, array, function, file_get_contents, file, content">
<meta name="description" content="file_get_contents php filesystem function example - reads a file and returns as string">
<style>
h3, h4{background:orange; color:#000089;}
h3{ padding:3px; margin:3px; font-size:22px;}
h4{ padding:2px; margin:2px; font-size:19px;}
p{padding:2px; margin:2px; color:#0099FD;}
body{ background:#FFFFFB;}
</style>
</head>
<body style="text-align:left;">
<h3>file_get_contents php filesystem function example - reads a file and returns as string</h3>
<?php
/*
----------------------------------------------------------------------------------
let say we want to read a file's entire content as string in php, we can make it
by using file_get_contents
----------------------------------------------------------------------------------
*/
$filePath = "http://php-example-code.blogspot.com/2010/07/file-exists-php-filesystem-function.html";
echo "<h4>File to be red as string</h4>";
print "<p>$"."filePath = {$filePath}</p>";
print $fileContentAsString = file_get_contents($filePath);
/*
-------------------------------------------------------------------------------
1. you can change $filePath value dynamically to get different file's content
2. If any special characters in $filePath or URI use urlencode() to encode
-------------------------------------------------------------------------------
*/
/*
-------------------------------------------------------------------------------------------
this function rapidly used in professional programming to read a file's content as string
-------------------------------------------------------------------------------------------
*/
?>
</body>
</html>
file_get_contents php filesystem function example - reads a file and returns as string - output in the browser
Related Tutorial Examples
- Use of ELSE IF in PHP Tutorial Example
- Use of IF in PHP Tutorial Example
- Apache mod_rewrite Example - Forbidding Direct Script Access
- Apache mod_rewrite Example - SEO Friendly URLs
- Apache mod_rewrite Example - Hellow World!! Program Using Htaccess
- Apache mod_rewrite Example - MOD_Rewrite Status Test
- Check Apache Web Server Version
- 19 Examples to Learn MySQL
- 20 steps to make CakePHP Blog Project
- curl_version() - cURL or Client URL Version Information
No comments:
Post a Comment
leave your comments here..