★ wanayoo — archive 1999 http://www.php.net/manual/ja/function.file.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to ファイルシステム
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
ファイルシステム
* basename
* chgrp
* chmod
* chown
* clearstatcache
* copy
* delete
* dirname
* diskfreespace
* fclose
* feof
* fgetc
* fgetcsv
* fgets
* fgetss
* file
* file_exists
* fileatime
* filectime
* filegroup
* fileinode
* filemtime
* fileowner
* fileperms
* filesize
* filetype
* flock
* fopen
* fpassthru
* fputs
* fread
* fscanf
* fseek
* fstat
* ftell
* ftruncate
* fwrite
* set_file_buffer
* is_dir
* is_executable
* is_file
* is_link
* is_readable
* is_writeable
* link
* linkinfo
* mkdir
* pclose
* popen
* readfile
* readlink
* rename
* rewind
* rmdir
* stat
* lstat
* realpath
* symlink
* tempnam
* touch
* umask
* unlink
Manual: file
View the source code for this pageSearch the site



Previous page
 fgetss
 Updated
Sat, 12 Aug 2000
file_exists 
Next page


file

(PHP3 , PHP4 )

file -- ファイル全体を読み込んで配列に格納する

説明

array file (string filename [, int use_include_path])

readfile()と同じですが、file() はファイルを配列に入れて返すところが異なります。 配列の各要素はファイルの各行に対応します。改行記号はついたままと なります。

オプションの2番目の引数を使用して、これに"1"を設定することにより、 include_path のファイルの検索も行うことができます。


<?php
// Webページを配列として取得し、出力します。
$fcontents = file( 'http://www.php.net' );
while ( list( $line_num, $line ) = each( $fcontents ) ) {
   echo "<b>Line $line_num:</b> " . htmlspecialchars( $line ) . "<br>\n";
}

// Webページを文字列として取得します。
$fcontents = join( '', file( 'http://www.php.net' ) );
?>
      

readfile(),fopen(), popen()も参照下さい。


User Contributed Notes: file


php@interfaces.fr
20-Jul-1999 04:15
Be careful using this function while operating on MacOS files !!!
As described in the "get_meta_tags" function (http://www.php.net/manual/function.get-meta-tags.php3), php uses a native function to parse input of files, so Mac files won't work on unix platform : -(



sean@devhype.com
24-Sep-1999 06:34
Store the contents of the file in a variable called $contents. Then use this line to pull out all of the links, but make sure to remove the href= /old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2Fja%2Fout&y=1999 of each link in the array.
$tmp preg_match_all("|href=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2Fja%2F%28%5B%24%2F%5C&y=1999'\"a-zA-Z0-9][^\s>\'\"]+)|i",$contents,$linksarray);

NOTE: $linksarray[0][0] is the first link returned and $linksarray[0][1] is the next, so on and so forth.



billgr@sunoptics.caltech.edu
04-Feb-2000 01:33
When using file() with remote files, it doesn't seem to like to get a file from the local host. That is, running it on the server host.com, it doesn't want to get "http://www.host.com/"


discoone@discoone.com
18-Feb-2000 12:24
Getting files on the same web server works perfectly.
I'm using this function to retrieve some files which URLs are stored in a mysql database. Thus the correct use of the function itself as i used is :
<pre>

$url = 'http://www.thehost.it/thepath/thefile.htm';
$allfile = file($url);

</pre>

giving the entire URL with HTTP:// and so on it seems to work, at least under BSD/OS v. 4.0.1 , Zend engine v.0.90, Apache/1.3.1 PHP/4.0b2.



davidbullock@tech-center.com
23-Feb-2000 03:23
If the retrieval of the file fails, then instead of the variable being set to an array, it will be set to a boolean.


If you are accessing a virtual host (ala Apache) with HTTP, be sure that the IP you are resolving to is one that the vhost is bound on.



anonymous
23-Feb-2000 07:21
To sean@devhype.com,

That was a good example for ripping links out of html. I praise you! God you're a PHP god. I visit gelicon.com all the time, your PHP tutorials rule!



stralud@libero.it
15-Mar-2000 11:43
ATTENTION!!
If you have:

$array = file("filename");

the last character of the array element is the newline char. So if you use the array elements remember it.



caspian@linuxfreak.com
22-Mar-2000 12:50
So what is the opposite of this function? What is the easiest way to dump an array to a file? i.e. in Perl you can just say
print FILEHANDLE @array;



mayur@morelinux.com
29-Mar-2000 10:13
How do I open multiple files (File names stored in a array) in W+ moed and overwirte them with NEW content patched on the old HTML files ? Contents are stored in a mysql database ....
Thanks in advance !



cleong@organic.com
22-Apr-2000 05:09
Use chop() to remove the newline/return characters from the end of the lines.


mars@redplanetsw.com
07-Jul-2000 02:31
Opposite of this function would be something like:
<PRE>print implode("", $array);</PRE>
implode() joins an array of strings into a single string.



ted@php.net
10-Jul-2000 01:32
Here's a way to put the contents of a file into a mail message:
<pre>
$msg="";
while ( list( $line_num, $line ) = each( $fcontents ) ) {
// Throw away the line number.
$msg .= $line; // Append the line to the message.
}
//echo $msg; //Just to see it; remove for production.
mail($to, $subject, $msg);
</pre>



tribui@hotmail.com
11-Jul-2000 03:14
file() does not work with links?



dhickey@websitefactory.net
19-Jul-2000 12:51
You need to have PHP compiled with URL compliant fopen wrappers in order to use file on links.



25-Jul-2000 12:21
Does it support https,ssl ??


jay@webtechnw.com
25-Jul-2000 07:05
I need to parse a response from a webserver over https. A simple fopen statment seems to be close to what im looking for, however the default method is a GET request, where I must have a POST request. In short.. i need to post variables to a script on another server and then process its response.


php2eran@tromer.org
27-Jul-2000 12:47
In PHP 4.0.0 and lower, array elements are never longer than 8190 characters. Longer lines are split. This limitation was removed in PHP 4.0.1.



jay@webtechnw.com
27-Jul-2000 04:48
Problem solved.. If you are looking for a way to..Have PHP make an SSL encrypted post to a transaction server?
Use cURL. example..
http://www.faqts.com/knowledge-base/view.phtml/aid/697/fid/105/lang/en
or just go to
http://curl.haxx.se/



E.S.Verhoef@zap.a2000.nl
31-Jul-2000 11:10
Hi all,
is it possible to count the number of files in a certain directory?



micfur@hotmail.com
01-Aug-2000 03:50
Hi, I am getting this error returned :

Warning: File("http://www.php.net") - No such file or directory

when I try to use the 'file' function. Any ideas?

Thanks




 About Notes


Previous page
 fgetss
 Updated
Sat, 12 Aug 2000
file_exists 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.