copy file content to string variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

copy file content to string variable

Post by lipun4u »

Is there any function in php library that will copy the contents of a text file into string ??
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: copy file content to string variable

Post by omniuni »

I believe file_get_contents() is what you're looking for.

http://php.net/manual/en/function.file-get-contents.php

Use with stripslashes:

Code: Select all

 
//set file name
$file = 'myfile.html';
 
//echo contents of file
echo(stripslashes(file_get_contents($file)));
 
//echo contents of file exactly (will display special chars in browser)
echo(htmlentities(stripslashes(file_get_contents($file))));
 
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: copy file content to string variable

Post by lipun4u »

Thank you very much !!!! :lol:
Post Reply