PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO READ FILES INTO A STRING USING THE file_get_contents() FUNCTION IN PHP

PHP provides the simple file_get_contents() function to read the entire contents of a file into one long string. In it's simplest form, this function takes the file or a url as parameter.

Example :

<?

$myFile="test.txt";
$data=file_get_contents($myFile);

?>

You can also use this file_get_contents() function on urls as well and not just files as in the example below.

Example :

<?

$myFile="http://www.somesite.com/somepage.html";
$data=file_get_contents($myFile);

?>

The entire contents of the file is now stored in variable $data. If you echo $data, you will get the entire contents of this file outputted to your screen.

Home | Privacy Policy | Terms Of Use | Contact Us