<HTML ><HEAD ><TITLE >file</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Filesystem functions" HREF="ref.filesystem.html"><LINK REL="PREVIOUS" TITLE="fgetss" HREF="function.fgetss.html"><LINK REL="NEXT" TITLE="file_exists" HREF="function.file-exists.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.fgetss.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.file-exists.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.file" >file</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN8566" ></A >file -- read entire file into an array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN8569" ></A ><H2 >Description</H2 ><DIV CLASS="funcsynopsis" ><P ></P ><CODE CLASS="FUNCDEF" >array file</CODE >(string filename, int [<SPAN CLASS="optional" >use_include_path</SPAN >] );<P ></P ></DIV ><P > Identical to <A HREF="function.readfile.html" ><B CLASS="function" >readfile()</B ></A >, except that <B CLASS="function" >file()</B > returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. </P ><P > You can use the optional second parameter and set it to "1", if you want to search for the file in the <A HREF="configuration.html#ini.include-path" >include_path</A >, too. </P ><P > <DIV CLASS="informalexample" ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 <?php 3 // get a web page into an array and print it out 4 $fcontents = file( 'http://www.php.net' ); 5 while ( list( $line_num, $line ) = each( $fcontents ) ) { 6 echo "<b>Line $line_num:</b> " . htmlspecialchars( $line ) . "<br>\n"; 7 } 8 9 // get a web page into a string 10 $fcontents = join( '', file( 'http://www.php.net' ) ); 11 ?> 12 </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > See also <A HREF="function.readfile.html" ><B CLASS="function" >readfile()</B ></A >, <A HREF="function.fopen.html" ><B CLASS="function" >fopen()</B ></A >, and <A HREF="function.popen.html" ><B CLASS="function" >popen()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.fgetss.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.file-exists.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >fgetss</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.filesystem.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >file_exists</TD ></TR ></TABLE ></DIV ></BODY ></HTML >