Page 1 of 1

copy file content to string variable

Posted: Thu Dec 24, 2009 8:18 am
by lipun4u
Is there any function in php library that will copy the contents of a text file into string ??

Re: copy file content to string variable

Posted: Thu Dec 24, 2009 8:36 am
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))));
 

Re: copy file content to string variable

Posted: Thu Dec 24, 2009 8:40 am
by lipun4u
Thank you very much !!!! :lol: