PHP 读åæ件çæ£ç¡®æ¹æ³_phpæå·§
程序员文章站
2024-02-08 17:30:16
...
让æ们ç®ä¸ç®æå¤å°ç§æ¹æ³
å¤çè¯¸å¦ PHP ä¹ç±»çç°ä»£ç¼ç¨è¯è¨çä¹è¶£ä¹ä¸å°±æ¯æ大éçé项å¯ç¨ãPHP å¯ä»¥è½»æ¾å°èµ¢å¾ Perl ç座å³éâThere's more than one way to do itâï¼å¹¶éåªæä¸ç§æ¹æ³å¯åè¿ä»¶äºï¼ï¼å°¤å ¶æ¯å¨æ件å¤çä¸ãä½æ¯å¨è¿ä¹å¤å¯ç¨çé项ä¸ï¼åªä¸ç§æ¯å®æä½ä¸çæä½³å·¥å ·ï¼å½ç¶ï¼å®é çæ¡åå³äºè§£ææ件çç®æ ï¼å æ¤å¼å¾è±æ¶é´æ¢ç©¶ææé项ã
å页é¦
ä¼ ç»ç fopen æ¹æ³
fopen æ¹æ³å¯è½æ¯ä»¥åç C å C++ ç¨åºåæçæçï¼å 为å¦ææ¨ä½¿ç¨è¿è¿äºè¯è¨ï¼é£ä¹å®ä»¬æå¤æå°é½æ¯æ¨å·²ææ¡å¤å¹´çå·¥å ·ã对äºè¿äºæ¹æ³ä¸çä»»ä½ä¸ç§ï¼éè¿ä½¿ç¨ fopenï¼ç¨äºè¯»åæ°æ®çå½æ°ï¼çæ åæ¹æ³æå¼æ件ï¼ç¶åä½¿ç¨ fclose å ³éæ件ï¼å¦æ¸ å 1 æ示ã
æ¸ å 1. ç¨ fgets æå¼å¹¶è¯»åæ件
$file_handle = fopen("myfile", "r");
while (!feof($file_handle)) {
$line = fgets($file_handle);
echo $line;
}
fclose($file_handle);
è½ç¶å¤§å¤æ°å ·æå¤å¹´ç¼ç¨ç»éªçç¨åºåé½çæè¿äºå½æ°ï¼ä½æ¯è®©æ对è¿äºå½æ°è¿è¡å解ãææå°æ§è¡ä»¥ä¸æ¥éª¤ï¼
æå¼æ件ã$file_handle åå¨äºä¸ä¸ªå¯¹æ件æ¬èº«çå¼ç¨ã
æ£æ¥æ¨æ¯å¦å·²å°è¾¾æ件çæ«å°¾ã
继ç»è¯»åæ件ï¼ç´è³å°è¾¾æ件æ«å°¾ï¼è¾¹è¯»åè¾¹æå°æ¯è¡ã
å ³éæ件ã
è®°ä½è¿äºæ¥éª¤ï¼æå°å顾å¨è¿é使ç¨çæ¯ä¸ªæ件å½æ°ã
fopen
fopen å½æ°å°å建ä¸æ件çè¿æ¥ãæä¹æ以说âå建è¿æ¥âï¼æ¯å 为é¤äºæå¼æ件ä¹å¤ï¼fopen è¿å¯ä»¥æå¼ä¸ä¸ª URLï¼$fh = fopen("http://127.0.0.1/", "r");
è¿è¡ä»£ç å°å建ä¸ä¸ªä¸ä»¥ä¸é¡µé¢çè¿æ¥ï¼å¹¶å 许æ¨å¼å§å读åä¸ä¸ªæ¬å°æ件ä¸æ ·è¯»åå®ã
æ³¨ï¼ fopen ä¸ä½¿ç¨ç "r" å°æ示æ件以åªè¯»æ¹å¼æå¼ãç±äºå°æ°æ®åå ¥æ件ä¸å¨æ¬æç讨论èå´å ï¼å æ¤æå°ä¸ååºææå ¶ä»é项ãä½æ¯ï¼å¦ææ¯ä»äºè¿å¶æ件读å以è·å¾è·¨å¹³å°å ¼å®¹æ§ï¼ååºå½å° "r" æ´æ¹ä¸º "rb"ãç¨åæ¨å°çå°è¿æ ·ç示ä¾ã
feof
feof å½ä»¤å°æ£æµæ¨æ¯å¦å·²ç»è¯»å°æ件çæ«å°¾å¹¶è¿å True æ Falseãæ¸ å 1 ä¸ç循ç¯å°ç»§ç»æ§è¡ï¼ç´è³æ¨è¾¾å°æ件âmyfileâçæ«å°¾ã注ï¼å¦æ读åçæ¯ URL 并ä¸å¥æ¥åç±äºä¸åæä»»ä½æ°æ®å¯ä»¥è¯»åèè¶ æ¶ï¼å feof ä¹å°è¿å Falseã
fclose
ååè·³è³æ¸ å 1 çæ«å°¾ï¼fclose å°å®ç°ä¸ fopen ç¸åçåè½ï¼å®å°å ³éæåæ件æ URL çè¿æ¥ãæ§è¡æ¤å½æ°åï¼æ¨å°ä¸åè½å¤ä»æ件æå¥æ¥åä¸è¯»åä»»ä½ä¿¡æ¯ã
fgets
å¨æ¸ å 1 ä¸åè·³å è¡ï¼æ¨å°±å°è¾¾äºæ件å¤ççæ ¸å¿ï¼å®é 读åæ件ãfgets å½æ°æ¯å¤ç第ä¸ä¸ªç¤ºä¾çé¦éæ¦å¨ãå®å°ä»æ件ä¸æåä¸è¡æ°æ®å¹¶å°å ¶ä½ä¸ºå符串è¿åãå¨é£ä¹åï¼æ¨å¯ä»¥æå°æè 以å«çæ¹å¼å¤çæ°æ®ãæ¸ å 1 ä¸ç示ä¾å°ç²¾ç»å°æå°æ´ä¸ªæ件ã
å¦æå³å®éå¶å¤çæ°æ®åç大å°ï¼æ¨å¯ä»¥å°ä¸ä¸ªåæ°æ·»å å° fgets ä¸éå¶æ大è¡é¿åº¦ãä¾å¦ï¼ä½¿ç¨ä»¥ä¸ä»£ç å°è¡é¿åº¦éå¶ä¸º 80 个å符ï¼$string = fgets($file_handle, 81);
åæ³ C ä¸çâ âå符串æ«å°¾ç»æ¢ç¬¦ï¼å°é¿åº¦è®¾ä¸ºæ¯å®é æéå¼å¤§ä¸çæ°åãå èï¼å¦æéè¦ 80 个å符ï¼å以ä¸ç¤ºä¾ä½¿ç¨ 81ãåºå »æ以ä¸ä¹ æ¯ï¼åªè¦å¯¹æ¤å½æ°ä½¿ç¨è¡éå¶ï¼å°±æ·»å 该é¢å¤å符ã
fread
fgets å½æ°æ¯å¤ä¸ªæ件读åå½æ°ä¸æä¸ä¸ä¸ªå¯ç¨çãå®æ¯ä¸ä¸ªæ´å¸¸ç¨çå½æ°ï¼å 为éè¡è§£æé常ä¼ææä¹ãäºå®ä¸ï¼å ä¸ªå ¶ä»å½æ°ä¹å¯ä»¥æä¾ç±»ä¼¼åè½ãä½æ¯ï¼æ¨å¹¶éæ»æ¯éè¦éè¡è§£æã
è¿æ¶å°±éè¦ä½¿ç¨ freadãfread å½æ°ä¸ fgets çå¤çç®æ ç¥æä¸åï¼å®è¶äºä»äºè¿å¶æ件ï¼å³ï¼å¹¶é主è¦å å«äººç±»å¯é 读çææ¬çæ件ï¼ä¸è¯»åä¿¡æ¯ãç±äºâè¡âçæ¦å¿µä¸äºè¿å¶æ件æ å ³ï¼é»è¾æ°æ®ç»æé常é½ä¸æ¯ç±æ°è¡ç»æ¢ï¼ï¼å æ¤æ¨å¿ é¡»æå®éè¦è¯»å ¥çåèæ°ã$fh = fopen("myfile", "rb");
$data = fread($file_handle, 4096);
使ç¨äºè¿å¶æ°æ®
注æï¼æ¤å½æ°ç示ä¾å·²ç»ä½¿ç¨äºç¥å¾®ä¸åäº fopen çåæ°ãå½å¤çäºè¿å¶æ°æ®æ¶ï¼å§ç»è¦è®°å¾å° b é项å å«å¨ fopen ä¸ãå¦æè·³è¿è¿ä¸ç¹ï¼Microsoft® Windows® ç³»ç»å¯è½æ æ³æ£ç¡®å¤çæ件ï¼å 为å®ä»¬å°ä»¥ä¸åçæ¹å¼å¤çæ°è¡ãå¦æå¤ççæ¯ Linux® ç³»ç»ï¼æå ¶ä»æ个 UNIX® åç§ï¼ï¼åè¿å¯è½ç似没ä»ä¹å ³ç³»ãä½å³ä½¿ä¸æ¯é对 Windows å¼åçï¼è¿æ ·åä¹å°è·å¾è¯å¥½ç跨平å°å¯ç»´æ¤æ§ï¼å¹¶ä¸ä¹æ¯åºå½éµå¾ªçä¸ä¸ªå¥½ä¹ æ¯ã
以ä¸ä»£ç å°è¯»å 4,096 åè (4 KB) çæ°æ®ã注ï¼ä¸ç®¡æå®å¤å°åèï¼fread é½ä¸ä¼è¯»åè¶ è¿ 8,192 个åè (8 KB)ã
åå®æ件大å°ä¸è¶ è¿ 8 KBï¼å以ä¸ä»£ç åºå½è½å°æ´ä¸ªæä»¶è¯»å ¥ä¸ä¸ªå符串ã$fh = fopen("myfile", "rb");
$data = fread($fh, filesize("myfile"));
fclose($fh);
å¦ææ件é¿åº¦å¤§äºæ¤å¼ï¼ååªè½ä½¿ç¨å¾ªç¯å°å ¶ä½å å®¹è¯»å ¥ã
fscanf
åå°å符串å¤çï¼fscanf åæ ·éµå¾ªä¼ ç»ç C æ件åºå½æ°ãå¦ææ¨ä¸çæå®ï¼å fscanf å°æå段æ°æ®ä»æä»¶è¯»å ¥åéä¸ãlist ($field1, $field2, $field3) = fscanf($fh, "%s %s %s");
æ¤å½æ°ä½¿ç¨çæ ¼å¼å符串å¨å¾å¤å°æ¹é½ææè¿°ï¼å¦ PHP.net ä¸ï¼ï¼æ å¨æ¤ä¸åèµè¿°ãå¯ä»¥è¿æ ·è¯´ï¼åç¬¦ä¸²æ ¼å¼åæ为çµæ´»ãå¼å¾æ³¨æçæ¯ææå段é½æ¾å¨å½æ°çè¿åå¼ä¸ãï¼å¨ C ä¸ï¼å®ä»¬é½è¢«ä½ä¸ºåæ°ä¼ éãï¼
fgetss
fgetss å½æ°ä¸åäºä¼ ç»æ件å½æ°å¹¶ä½¿æ¨è½æ´å¥½å°äºè§£ PHP çåéã该å½æ°çåè½ç±»ä¼¼äº fgets å½æ°ï¼ä½å°å»æåç°çä»»ä½ HTML æ PHP æ è®°ï¼åªçä¸çº¯ææ¬ãæ¥çå¦ä¸æ示ç HTML æ件ã
æ¸ å 2. æ ·ä¾ HTML æ件
My title
ç¶åéè¿ fgetss å½æ°è¿æ»¤å®ã
æ¸ å 3. ä½¿ç¨ fgetss
$file_handle = fopen("myfile", "r");
while (!feof($file_handle)) {
echo = fgetss($file_handle);
}
fclose($file_handle);
以ä¸æ¯è¾åºï¼ My title
If you understand what "Cause there ain't no one for to give you no pain"
means then you listen to too much of the band America
fpassthru å½æ°
æ 论ææ ·è¯»åæ件ï¼æ¨é½å¯ä»¥ä½¿ç¨ fpassthru å°å ¶ä½æ°æ®è½¬å¨å°æ åè¾åºééãfpassthru($fh);
æ¤å¤ï¼æ¤å½æ°å°æå°æ°æ®ï¼å æ¤æ é使ç¨åéè·åæ°æ®ã
é线æ§æ件å¤çï¼è·³è·è®¿é®
å½ç¶ï¼ä»¥ä¸å½æ°åªå 许顺åºè¯»åæ件ãæ´å¤æçæ件å¯è½è¦æ±æ¨æ¥å跳转å°æ件çä¸åé¨åãè¿æ¶å°±ç¨å¾ç fseek äºãfseek($fh, 0);
以ä¸ç¤ºä¾å°è·³è½¬åæ件çå¼å¤´ãå¦æä¸éè¦å®å ¨è¿å ââ æ们å¯è®¾å®è¿åååè ââ ç¶åå°±å¯ä»¥è¿æ ·åï¼fseek($fh, 1024);
ä» PHP V4.0 å¼å§ï¼æ¨æä¸äºå ¶ä»é项ãä¾å¦ï¼å¦æéè¦ä»å½åä½ç½®åå跳转 100 个åèï¼åå¯ä»¥å°è¯ä½¿ç¨ï¼fseek($fh, 100, SEEK_CUR);
类似å°ï¼å¯ä»¥ä½¿ç¨ä»¥ä¸ä»£ç åå跳转 100 个åèï¼fseek($fh, -100, SEEK_CUR);
å¦æéè¦åå跳转è³æ件æ«å°¾å 100 个åèå¤ï¼ååºä½¿ç¨ SEEK_ENDãfseek($fh, -100, SEEK_END);
å¨å°è¾¾æ°ä½ç½®åï¼å¯ä»¥ä½¿ç¨ fgetsãfscanf æä»»ä½å ¶ä»æ¹æ³è¯»åæ°æ®ã
注ï¼ä¸è½å° fseek ç¨äºå¼ç¨ URL çæ件å¤çã
å页é¦
æåæ´ä¸ªæ件
ç°å¨ï¼æ们å°æ¥è§¦å°ä¸äº PHP çæ´ç¬ç¹çæ件å¤çåè½ï¼ç¨ä¸ä¸¤è¡å¤ç大åæ°æ®ãä¾å¦ï¼å¦ä½æåæä»¶å¹¶å¨ Web 页é¢ä¸æ¾ç¤ºå ¶å ¨é¨å 容ï¼å¥½çï¼æ¨çå°äº fgets 使ç¨å¾ªç¯ç示ä¾ãä½æ¯å¦ä½è½å¤ä½¿æ¤è¿ç¨åå¾æ´ç®åï¼ç¨ fgetcontents ä¼ä½¿è¿ç¨è¶ 级ç®åï¼è¯¥æ¹æ³å°ææ´ä¸ªæ件æ¾å ¥ä¸ä¸ªå符串ä¸ã$my_file = file_get_contents("myfilename");
echo $my_file;
è½ç¶å®ä¸æ¯æ好çåæ³ï¼ä½æ¯å¯ä»¥å°æ¤å½ä»¤æ´ç®æå°å为ï¼echo file_get_contents("myfilename");
æ¬æ主è¦ä»ç»çæ¯å¦ä½å¤çæ¬å°æ件ï¼ä½æ¯å¼å¾æ³¨æçæ¯æ¨è¿å¯ä»¥ç¨è¿äºå½æ°æåãåæ¾å解æå ¶ä» Web 页é¢ãecho file_get_contents("http://127.0.0.1/");
æ¤å½ä»¤çæäºï¼$fh = fopen("http://127.0.0.1/", "r");
fpassthru($fh);
æ¨ä¸å®ä¼æ¥çæ¤å½ä»¤å¹¶è®¤ä¸ºï¼âé£è¿æ¯å¤ªè´¹åâãPHP å¼å人ååææ¨ççæ³ãå æ¤å¯ä»¥å°ä»¥ä¸å½ä»¤ç¼©ç为ï¼readfile("http://127.0.0.1/");
readfile å½æ°å°ææ件æ Web 页é¢çå ¨é¨å 容转å¨å°é»è®¤çè¾åºç¼å²åºãé»è®¤æ åµä¸ï¼å¦æ失败ï¼æ¤å½ä»¤å°æå°é误æ¶æ¯ãè¦é¿å æ¤è¡ä¸ºï¼å¦æéè¦ï¼ï¼è¯·å°è¯ï¼@readfile("http://127.0.0.1/");
å½ç¶ï¼å¦æç¡®å®éè¦è§£ææ件ï¼å file_get_contents è¿åçå个å符串å¯è½æäºè®©äººåä¸æ¶ãæ¨ç第ä¸ååºå¯è½æ¯ç¨ split() å½æ°å°å®å解ä¸ä¸ã$array = split("\n", file_get_contents("myfile"));
ä½æ¯æ¢ç¶å·²ç»æä¸ä¸ªå¾å¥½çå½æ°ä¸ºæ¨æ§è¡æ¤æä½ä¸ºä»ä¹è¿è¦è¿æ ·å¤§è´¹å¨ç« ï¼PHP ç file() å½æ°ä¸æ¥å³å¯å®ææ¤æä½ï¼å®å°è¿åå为è¥å¹²è¡çå符串æ°ç»ã$array = file("myfile");
åºå½æ³¨æçæ¯ï¼ä»¥ä¸ä¸¤ä¸ªç¤ºä¾æä¸ç¹ç»å¾®å·®å«ãè½ç¶ split å½ä»¤å°å é¤æ°è¡ï¼ä½æ¯å½ä½¿ç¨ file å½ä»¤ï¼ä¸ fgets å½ä»¤ä¸æ ·ï¼æ¶ï¼æ°è¡ä»å°è¢«éå å°æ°ç»ä¸çå符串ä¸ã
ä½æ¯ï¼PHP çåéè¿è¿ä¸æ¢äºæ¤ãæ¨å¯ä»¥å¨ä¸æ¡å½ä»¤ä¸ä½¿ç¨ parse_ini_file 解ææ´ä¸ª PHP æ ·å¼ç .ini æ件ãparse_ini_file å½ä»¤æ¥åç±»ä¼¼æ¸ å 4 æ示çæ件ã
æ¸ å 4. æ ·ä¾ .ini æ件
; Comment
[personal information]
name = "King Arthur"
quest = To seek the holy grail
favorite color = Blue
[more stuff]
Samuel Clemens = Mark Twain
Caryn Johnson = Whoopi Goldberg
以ä¸å½ä»¤å°ææ¤æ件转å¨ä¸ºæ°ç»ï¼ç¶åæå°è¯¥æ°ç»ï¼$file_array = parse_ini_file("holy_grail.ini");
print_r $file_array;
以ä¸è¾åºçæ¯ç»æï¼
Listing 5. è¾åº
Array
(
[name] => King Arthur
[quest] => To seek the Holy Grail
[favorite color] => Blue
[Samuel Clemens] => Mark Twain
[Caryn Johnson] => Whoopi Goldberg
)
å½ç¶ï¼æ¨å¯è½æ³¨æå°æ¤å½ä»¤å并äºå个é¨åãè¿æ¯é»è®¤è¡ä¸ºï¼ä½æ¯æ¨å¯ä»¥éè¿å°ç¬¬äºä¸ªåæ°ä¼ éç» parse_ini_file è½»æ¾å°ä¿®æ£å®ï¼process_sectionsï¼è¿æ¯ä¸ä¸ªå¸å°ååéãå° process_sections 设为 Trueã$file_array = parse_ini_file("holy_grail.ini", true);
print_r $file_array;
并ä¸æ¨å°è·å¾ä»¥ä¸è¾åºï¼
æ¸ å 6. è¾åº
Array
(
[personal information] => Array
(
[name] => King Arthur
[quest] => To seek the Holy Grail
[favorite color] => Blue
)
[more stuff] => Array
(
[Samuel Clemens] => Mark Twain
[Caryn Johnson] => Whoopi Goldberg
)
)
PHP å°ææ°æ®æ¾å ¥å¯ä»¥è½»æ¾è§£æçå¤ç»´æ°ç»ä¸ã
å¯¹äº PHP æ件å¤çæ¥è¯´ï¼è¿åªæ¯å°å±±ä¸è§ãè¯¸å¦ tidy_parse_file å xml_parse ä¹ç±»çæ´å¤æçå½æ°å¯ä»¥åå«å¸®å©æ¨å¤ç HTML å XML ææ¡£ãæå ³è¿äºç¹æ®å½æ°ç使ç¨ç»èï¼è¯·åé åèèµæãå¦ææ¨è¦å¤çé£äºç±»åçæ件ï¼åé£äºåèèµæå¼å¾ä¸çï¼ä½ä¸å¿ è¿åº¦èèæ¬æä¸è°å°çæ¯ç§å¯è½éå°çæ件类åï¼ä¸é¢æ¯ä¸äºç¨äºå¤çå°ç®å为æ¢ä»ç»çå½æ°çå¾å¥½çéç¨è§åã
å页é¦
æä½³å®è·µ
ç»ä¸è¦åå®ç¨åºä¸çä¸åé½å°æ计åè¿è¡ãä¾å¦ï¼å¦ææ¨è¦æ¥æ¾çæ件已被移å¨è¯¥å½å¦ä½ï¼å¦ææé已被æ¹åèæ æ³è¯»åå ¶å 容åå½å¦ä½ï¼æ¨å¯ä»¥éè¿ä½¿ç¨ file_exists å is_readable é¢å æ£æ¥è¿äºé®é¢ã
æ¸ å 7. ä½¿ç¨ file_exists å is_readable
$filename = "myfile";
if (file_exists($filename) && is_readable ($filename)) {
$fh = fopen($filename, "r");
# Processing
fclose($fh);
}
ä½æ¯ï¼å¨å®è·µä¸ï¼ç¨è¿æ ·ç代ç å¯è½å¤ªç¹çäºãå¤ç fopen çè¿åå¼æ´ç®å并ä¸æ´åç¡®ãif ($fh = fopen($filename, "r")) {
# Processing
fclose($fh);
}
ç±äºå¤±è´¥æ¶ fopen å°è¿å Falseï¼è¿å°ç¡®ä¿ä» å½æ件æåæå¼åææ§è¡æ件å¤çãå½ç¶ï¼å¦ææ件ä¸åå¨æè ä¸å¯è¯»ï¼æ¨å¯ä»¥ææä¸ä¸ªè´è¿åå¼ãè¿å°ä½¿è¿ä¸ªæ£æ¥å¯ä»¥æ£æ¥ææå¯è½éå°çé®é¢ãæ¤å¤ï¼å¦ææå¼å¤±è´¥ï¼å¯ä»¥éåºç¨åºæ让ç¨åºæ¾ç¤ºé误æ¶æ¯ã
å¦ fopen å½æ°ä¸æ ·ï¼file_get_contentsãfile å readfile å½æ°é½å¨æå¼å¤±è´¥æå¤çæ件失败æ¶è¿å Falseãfgetsãfgetssãfreadãfscanf å fclose å½æ°å¨åºéæ¶ä¹è¿å Falseãå½ç¶ï¼é¤ fclose 以å¤ï¼æ¨å¯è½å·²ç»å¯¹è¿äºå½æ°çè¿åå¼é½è¿è¡äºå¤çãä½¿ç¨ fclose æ¶ï¼å³ä½¿æ件å¤çæªæ£å¸¸å ³éï¼ä¹ä¸ä¼æ§è¡ä»ä¹æä½ï¼å æ¤é常ä¸å¿ æ£æ¥ fclose çè¿åå¼ã
å页é¦
ç±æ¨æ¥éæ©
PHP ä¸ç¼ºè¯»åå解ææ件çæææ¹æ³ãè¯¸å¦ fread ä¹ç±»çå ¸åå½æ°å¯è½å¨å¤§å¤æ°æ¶åé½æ¯æä½³çéæ©ï¼æè å½ readfile å好è½æ»¡è¶³ä»»å¡éè¦æ¶ï¼æ¨å¯è½ä¼åç°èªå·±æ´ä¸º readfile çç®åæå¸å¼ãå®å®é ä¸åå³äºæè¦å®æçæä½ã
å¦æè¦å¤ç大éæ°æ®ï¼fscanf å°è½è¯æèªå·±çä»·å¼å¹¶æ¯ä½¿ç¨ file é带 split å sprintf å½ä»¤æ´ææçãç¸åï¼å¦æè¦åæ¾åªåäºå°è®¸ä¿®æ¹ç大éææ¬ï¼åä½¿ç¨ fileãfile_get_contents æ readfile å¯è½æ´åéãä½¿ç¨ PHP è¿è¡ç¼åæè å建æå®ç代çæå¡å¨æ¶å¯è½å°±å±äºè¿ç§æ åµã
PHP ç»æ¨æä¾äºå¤§éå¤çæ件çå·¥å ·ãæ·±å ¥äºè§£è¿äºå·¥å ·å¹¶äºè§£åªäºå·¥å ·æéåäºè¦å¤çç项ç®ãæ¨å·²æ¥æå¾å¤çéæ©ï¼å æ¤å¥½å¥½å°å©ç¨å®ä»¬äº«åä½¿ç¨ PHP å¤çæ件çä¹è¶£ã
å¤çè¯¸å¦ PHP ä¹ç±»çç°ä»£ç¼ç¨è¯è¨çä¹è¶£ä¹ä¸å°±æ¯æ大éçé项å¯ç¨ãPHP å¯ä»¥è½»æ¾å°èµ¢å¾ Perl ç座å³éâThere's more than one way to do itâï¼å¹¶éåªæä¸ç§æ¹æ³å¯åè¿ä»¶äºï¼ï¼å°¤å ¶æ¯å¨æ件å¤çä¸ãä½æ¯å¨è¿ä¹å¤å¯ç¨çé项ä¸ï¼åªä¸ç§æ¯å®æä½ä¸çæä½³å·¥å ·ï¼å½ç¶ï¼å®é çæ¡åå³äºè§£ææ件çç®æ ï¼å æ¤å¼å¾è±æ¶é´æ¢ç©¶ææé项ã
å页é¦
ä¼ ç»ç fopen æ¹æ³
fopen æ¹æ³å¯è½æ¯ä»¥åç C å C++ ç¨åºåæçæçï¼å 为å¦ææ¨ä½¿ç¨è¿è¿äºè¯è¨ï¼é£ä¹å®ä»¬æå¤æå°é½æ¯æ¨å·²ææ¡å¤å¹´çå·¥å ·ã对äºè¿äºæ¹æ³ä¸çä»»ä½ä¸ç§ï¼éè¿ä½¿ç¨ fopenï¼ç¨äºè¯»åæ°æ®çå½æ°ï¼çæ åæ¹æ³æå¼æ件ï¼ç¶åä½¿ç¨ fclose å ³éæ件ï¼å¦æ¸ å 1 æ示ã
æ¸ å 1. ç¨ fgets æå¼å¹¶è¯»åæ件
$file_handle = fopen("myfile", "r");
while (!feof($file_handle)) {
$line = fgets($file_handle);
echo $line;
}
fclose($file_handle);
è½ç¶å¤§å¤æ°å ·æå¤å¹´ç¼ç¨ç»éªçç¨åºåé½çæè¿äºå½æ°ï¼ä½æ¯è®©æ对è¿äºå½æ°è¿è¡å解ãææå°æ§è¡ä»¥ä¸æ¥éª¤ï¼
æå¼æ件ã$file_handle åå¨äºä¸ä¸ªå¯¹æ件æ¬èº«çå¼ç¨ã
æ£æ¥æ¨æ¯å¦å·²å°è¾¾æ件çæ«å°¾ã
继ç»è¯»åæ件ï¼ç´è³å°è¾¾æ件æ«å°¾ï¼è¾¹è¯»åè¾¹æå°æ¯è¡ã
å ³éæ件ã
è®°ä½è¿äºæ¥éª¤ï¼æå°å顾å¨è¿é使ç¨çæ¯ä¸ªæ件å½æ°ã
fopen
fopen å½æ°å°å建ä¸æ件çè¿æ¥ãæä¹æ以说âå建è¿æ¥âï¼æ¯å 为é¤äºæå¼æ件ä¹å¤ï¼fopen è¿å¯ä»¥æå¼ä¸ä¸ª URLï¼$fh = fopen("http://127.0.0.1/", "r");
è¿è¡ä»£ç å°å建ä¸ä¸ªä¸ä»¥ä¸é¡µé¢çè¿æ¥ï¼å¹¶å 许æ¨å¼å§å读åä¸ä¸ªæ¬å°æ件ä¸æ ·è¯»åå®ã
æ³¨ï¼ fopen ä¸ä½¿ç¨ç "r" å°æ示æ件以åªè¯»æ¹å¼æå¼ãç±äºå°æ°æ®åå ¥æ件ä¸å¨æ¬æç讨论èå´å ï¼å æ¤æå°ä¸ååºææå ¶ä»é项ãä½æ¯ï¼å¦ææ¯ä»äºè¿å¶æ件读å以è·å¾è·¨å¹³å°å ¼å®¹æ§ï¼ååºå½å° "r" æ´æ¹ä¸º "rb"ãç¨åæ¨å°çå°è¿æ ·ç示ä¾ã
feof
feof å½ä»¤å°æ£æµæ¨æ¯å¦å·²ç»è¯»å°æ件çæ«å°¾å¹¶è¿å True æ Falseãæ¸ å 1 ä¸ç循ç¯å°ç»§ç»æ§è¡ï¼ç´è³æ¨è¾¾å°æ件âmyfileâçæ«å°¾ã注ï¼å¦æ读åçæ¯ URL 并ä¸å¥æ¥åç±äºä¸åæä»»ä½æ°æ®å¯ä»¥è¯»åèè¶ æ¶ï¼å feof ä¹å°è¿å Falseã
fclose
ååè·³è³æ¸ å 1 çæ«å°¾ï¼fclose å°å®ç°ä¸ fopen ç¸åçåè½ï¼å®å°å ³éæåæ件æ URL çè¿æ¥ãæ§è¡æ¤å½æ°åï¼æ¨å°ä¸åè½å¤ä»æ件æå¥æ¥åä¸è¯»åä»»ä½ä¿¡æ¯ã
fgets
å¨æ¸ å 1 ä¸åè·³å è¡ï¼æ¨å°±å°è¾¾äºæ件å¤ççæ ¸å¿ï¼å®é 读åæ件ãfgets å½æ°æ¯å¤ç第ä¸ä¸ªç¤ºä¾çé¦éæ¦å¨ãå®å°ä»æ件ä¸æåä¸è¡æ°æ®å¹¶å°å ¶ä½ä¸ºå符串è¿åãå¨é£ä¹åï¼æ¨å¯ä»¥æå°æè 以å«çæ¹å¼å¤çæ°æ®ãæ¸ å 1 ä¸ç示ä¾å°ç²¾ç»å°æå°æ´ä¸ªæ件ã
å¦æå³å®éå¶å¤çæ°æ®åç大å°ï¼æ¨å¯ä»¥å°ä¸ä¸ªåæ°æ·»å å° fgets ä¸éå¶æ大è¡é¿åº¦ãä¾å¦ï¼ä½¿ç¨ä»¥ä¸ä»£ç å°è¡é¿åº¦éå¶ä¸º 80 个å符ï¼$string = fgets($file_handle, 81);
åæ³ C ä¸çâ âå符串æ«å°¾ç»æ¢ç¬¦ï¼å°é¿åº¦è®¾ä¸ºæ¯å®é æéå¼å¤§ä¸çæ°åãå èï¼å¦æéè¦ 80 个å符ï¼å以ä¸ç¤ºä¾ä½¿ç¨ 81ãåºå »æ以ä¸ä¹ æ¯ï¼åªè¦å¯¹æ¤å½æ°ä½¿ç¨è¡éå¶ï¼å°±æ·»å 该é¢å¤å符ã
fread
fgets å½æ°æ¯å¤ä¸ªæ件读åå½æ°ä¸æä¸ä¸ä¸ªå¯ç¨çãå®æ¯ä¸ä¸ªæ´å¸¸ç¨çå½æ°ï¼å 为éè¡è§£æé常ä¼ææä¹ãäºå®ä¸ï¼å ä¸ªå ¶ä»å½æ°ä¹å¯ä»¥æä¾ç±»ä¼¼åè½ãä½æ¯ï¼æ¨å¹¶éæ»æ¯éè¦éè¡è§£æã
è¿æ¶å°±éè¦ä½¿ç¨ freadãfread å½æ°ä¸ fgets çå¤çç®æ ç¥æä¸åï¼å®è¶äºä»äºè¿å¶æ件ï¼å³ï¼å¹¶é主è¦å å«äººç±»å¯é 读çææ¬çæ件ï¼ä¸è¯»åä¿¡æ¯ãç±äºâè¡âçæ¦å¿µä¸äºè¿å¶æ件æ å ³ï¼é»è¾æ°æ®ç»æé常é½ä¸æ¯ç±æ°è¡ç»æ¢ï¼ï¼å æ¤æ¨å¿ é¡»æå®éè¦è¯»å ¥çåèæ°ã$fh = fopen("myfile", "rb");
$data = fread($file_handle, 4096);
使ç¨äºè¿å¶æ°æ®
注æï¼æ¤å½æ°ç示ä¾å·²ç»ä½¿ç¨äºç¥å¾®ä¸åäº fopen çåæ°ãå½å¤çäºè¿å¶æ°æ®æ¶ï¼å§ç»è¦è®°å¾å° b é项å å«å¨ fopen ä¸ãå¦æè·³è¿è¿ä¸ç¹ï¼Microsoft® Windows® ç³»ç»å¯è½æ æ³æ£ç¡®å¤çæ件ï¼å 为å®ä»¬å°ä»¥ä¸åçæ¹å¼å¤çæ°è¡ãå¦æå¤ççæ¯ Linux® ç³»ç»ï¼æå ¶ä»æ个 UNIX® åç§ï¼ï¼åè¿å¯è½ç似没ä»ä¹å ³ç³»ãä½å³ä½¿ä¸æ¯é对 Windows å¼åçï¼è¿æ ·åä¹å°è·å¾è¯å¥½ç跨平å°å¯ç»´æ¤æ§ï¼å¹¶ä¸ä¹æ¯åºå½éµå¾ªçä¸ä¸ªå¥½ä¹ æ¯ã
以ä¸ä»£ç å°è¯»å 4,096 åè (4 KB) çæ°æ®ã注ï¼ä¸ç®¡æå®å¤å°åèï¼fread é½ä¸ä¼è¯»åè¶ è¿ 8,192 个åè (8 KB)ã
åå®æ件大å°ä¸è¶ è¿ 8 KBï¼å以ä¸ä»£ç åºå½è½å°æ´ä¸ªæä»¶è¯»å ¥ä¸ä¸ªå符串ã$fh = fopen("myfile", "rb");
$data = fread($fh, filesize("myfile"));
fclose($fh);
å¦ææ件é¿åº¦å¤§äºæ¤å¼ï¼ååªè½ä½¿ç¨å¾ªç¯å°å ¶ä½å å®¹è¯»å ¥ã
fscanf
åå°å符串å¤çï¼fscanf åæ ·éµå¾ªä¼ ç»ç C æ件åºå½æ°ãå¦ææ¨ä¸çæå®ï¼å fscanf å°æå段æ°æ®ä»æä»¶è¯»å ¥åéä¸ãlist ($field1, $field2, $field3) = fscanf($fh, "%s %s %s");
æ¤å½æ°ä½¿ç¨çæ ¼å¼å符串å¨å¾å¤å°æ¹é½ææè¿°ï¼å¦ PHP.net ä¸ï¼ï¼æ å¨æ¤ä¸åèµè¿°ãå¯ä»¥è¿æ ·è¯´ï¼åç¬¦ä¸²æ ¼å¼åæ为çµæ´»ãå¼å¾æ³¨æçæ¯ææå段é½æ¾å¨å½æ°çè¿åå¼ä¸ãï¼å¨ C ä¸ï¼å®ä»¬é½è¢«ä½ä¸ºåæ°ä¼ éãï¼
fgetss
fgetss å½æ°ä¸åäºä¼ ç»æ件å½æ°å¹¶ä½¿æ¨è½æ´å¥½å°äºè§£ PHP çåéã该å½æ°çåè½ç±»ä¼¼äº fgets å½æ°ï¼ä½å°å»æåç°çä»»ä½ HTML æ PHP æ è®°ï¼åªçä¸çº¯ææ¬ãæ¥çå¦ä¸æ示ç HTML æ件ã
æ¸ å 2. æ ·ä¾ HTML æ件
If you understand what "Cause there ain't no one for to give you no pain"
means then you listen to too much of the band America
ç¶åéè¿ fgetss å½æ°è¿æ»¤å®ã
æ¸ å 3. ä½¿ç¨ fgetss
$file_handle = fopen("myfile", "r");
while (!feof($file_handle)) {
echo = fgetss($file_handle);
}
fclose($file_handle);
以ä¸æ¯è¾åºï¼ My title
If you understand what "Cause there ain't no one for to give you no pain"
means then you listen to too much of the band America
fpassthru å½æ°
æ 论ææ ·è¯»åæ件ï¼æ¨é½å¯ä»¥ä½¿ç¨ fpassthru å°å ¶ä½æ°æ®è½¬å¨å°æ åè¾åºééãfpassthru($fh);
æ¤å¤ï¼æ¤å½æ°å°æå°æ°æ®ï¼å æ¤æ é使ç¨åéè·åæ°æ®ã
é线æ§æ件å¤çï¼è·³è·è®¿é®
å½ç¶ï¼ä»¥ä¸å½æ°åªå 许顺åºè¯»åæ件ãæ´å¤æçæ件å¯è½è¦æ±æ¨æ¥å跳转å°æ件çä¸åé¨åãè¿æ¶å°±ç¨å¾ç fseek äºãfseek($fh, 0);
以ä¸ç¤ºä¾å°è·³è½¬åæ件çå¼å¤´ãå¦æä¸éè¦å®å ¨è¿å ââ æ们å¯è®¾å®è¿åååè ââ ç¶åå°±å¯ä»¥è¿æ ·åï¼fseek($fh, 1024);
ä» PHP V4.0 å¼å§ï¼æ¨æä¸äºå ¶ä»é项ãä¾å¦ï¼å¦æéè¦ä»å½åä½ç½®åå跳转 100 个åèï¼åå¯ä»¥å°è¯ä½¿ç¨ï¼fseek($fh, 100, SEEK_CUR);
类似å°ï¼å¯ä»¥ä½¿ç¨ä»¥ä¸ä»£ç åå跳转 100 个åèï¼fseek($fh, -100, SEEK_CUR);
å¦æéè¦åå跳转è³æ件æ«å°¾å 100 个åèå¤ï¼ååºä½¿ç¨ SEEK_ENDãfseek($fh, -100, SEEK_END);
å¨å°è¾¾æ°ä½ç½®åï¼å¯ä»¥ä½¿ç¨ fgetsãfscanf æä»»ä½å ¶ä»æ¹æ³è¯»åæ°æ®ã
注ï¼ä¸è½å° fseek ç¨äºå¼ç¨ URL çæ件å¤çã
å页é¦
æåæ´ä¸ªæ件
ç°å¨ï¼æ们å°æ¥è§¦å°ä¸äº PHP çæ´ç¬ç¹çæ件å¤çåè½ï¼ç¨ä¸ä¸¤è¡å¤ç大åæ°æ®ãä¾å¦ï¼å¦ä½æåæä»¶å¹¶å¨ Web 页é¢ä¸æ¾ç¤ºå ¶å ¨é¨å 容ï¼å¥½çï¼æ¨çå°äº fgets 使ç¨å¾ªç¯ç示ä¾ãä½æ¯å¦ä½è½å¤ä½¿æ¤è¿ç¨åå¾æ´ç®åï¼ç¨ fgetcontents ä¼ä½¿è¿ç¨è¶ 级ç®åï¼è¯¥æ¹æ³å°ææ´ä¸ªæ件æ¾å ¥ä¸ä¸ªå符串ä¸ã$my_file = file_get_contents("myfilename");
echo $my_file;
è½ç¶å®ä¸æ¯æ好çåæ³ï¼ä½æ¯å¯ä»¥å°æ¤å½ä»¤æ´ç®æå°å为ï¼echo file_get_contents("myfilename");
æ¬æ主è¦ä»ç»çæ¯å¦ä½å¤çæ¬å°æ件ï¼ä½æ¯å¼å¾æ³¨æçæ¯æ¨è¿å¯ä»¥ç¨è¿äºå½æ°æåãåæ¾å解æå ¶ä» Web 页é¢ãecho file_get_contents("http://127.0.0.1/");
æ¤å½ä»¤çæäºï¼$fh = fopen("http://127.0.0.1/", "r");
fpassthru($fh);
æ¨ä¸å®ä¼æ¥çæ¤å½ä»¤å¹¶è®¤ä¸ºï¼âé£è¿æ¯å¤ªè´¹åâãPHP å¼å人ååææ¨ççæ³ãå æ¤å¯ä»¥å°ä»¥ä¸å½ä»¤ç¼©ç为ï¼readfile("http://127.0.0.1/");
readfile å½æ°å°ææ件æ Web 页é¢çå ¨é¨å 容转å¨å°é»è®¤çè¾åºç¼å²åºãé»è®¤æ åµä¸ï¼å¦æ失败ï¼æ¤å½ä»¤å°æå°é误æ¶æ¯ãè¦é¿å æ¤è¡ä¸ºï¼å¦æéè¦ï¼ï¼è¯·å°è¯ï¼@readfile("http://127.0.0.1/");
å½ç¶ï¼å¦æç¡®å®éè¦è§£ææ件ï¼å file_get_contents è¿åçå个å符串å¯è½æäºè®©äººåä¸æ¶ãæ¨ç第ä¸ååºå¯è½æ¯ç¨ split() å½æ°å°å®å解ä¸ä¸ã$array = split("\n", file_get_contents("myfile"));
ä½æ¯æ¢ç¶å·²ç»æä¸ä¸ªå¾å¥½çå½æ°ä¸ºæ¨æ§è¡æ¤æä½ä¸ºä»ä¹è¿è¦è¿æ ·å¤§è´¹å¨ç« ï¼PHP ç file() å½æ°ä¸æ¥å³å¯å®ææ¤æä½ï¼å®å°è¿åå为è¥å¹²è¡çå符串æ°ç»ã$array = file("myfile");
åºå½æ³¨æçæ¯ï¼ä»¥ä¸ä¸¤ä¸ªç¤ºä¾æä¸ç¹ç»å¾®å·®å«ãè½ç¶ split å½ä»¤å°å é¤æ°è¡ï¼ä½æ¯å½ä½¿ç¨ file å½ä»¤ï¼ä¸ fgets å½ä»¤ä¸æ ·ï¼æ¶ï¼æ°è¡ä»å°è¢«éå å°æ°ç»ä¸çå符串ä¸ã
ä½æ¯ï¼PHP çåéè¿è¿ä¸æ¢äºæ¤ãæ¨å¯ä»¥å¨ä¸æ¡å½ä»¤ä¸ä½¿ç¨ parse_ini_file 解ææ´ä¸ª PHP æ ·å¼ç .ini æ件ãparse_ini_file å½ä»¤æ¥åç±»ä¼¼æ¸ å 4 æ示çæ件ã
æ¸ å 4. æ ·ä¾ .ini æ件
; Comment
[personal information]
name = "King Arthur"
quest = To seek the holy grail
favorite color = Blue
[more stuff]
Samuel Clemens = Mark Twain
Caryn Johnson = Whoopi Goldberg
以ä¸å½ä»¤å°ææ¤æ件转å¨ä¸ºæ°ç»ï¼ç¶åæå°è¯¥æ°ç»ï¼$file_array = parse_ini_file("holy_grail.ini");
print_r $file_array;
以ä¸è¾åºçæ¯ç»æï¼
Listing 5. è¾åº
Array
(
[name] => King Arthur
[quest] => To seek the Holy Grail
[favorite color] => Blue
[Samuel Clemens] => Mark Twain
[Caryn Johnson] => Whoopi Goldberg
)
å½ç¶ï¼æ¨å¯è½æ³¨æå°æ¤å½ä»¤å并äºå个é¨åãè¿æ¯é»è®¤è¡ä¸ºï¼ä½æ¯æ¨å¯ä»¥éè¿å°ç¬¬äºä¸ªåæ°ä¼ éç» parse_ini_file è½»æ¾å°ä¿®æ£å®ï¼process_sectionsï¼è¿æ¯ä¸ä¸ªå¸å°ååéãå° process_sections 设为 Trueã$file_array = parse_ini_file("holy_grail.ini", true);
print_r $file_array;
并ä¸æ¨å°è·å¾ä»¥ä¸è¾åºï¼
æ¸ å 6. è¾åº
Array
(
[personal information] => Array
(
[name] => King Arthur
[quest] => To seek the Holy Grail
[favorite color] => Blue
)
[more stuff] => Array
(
[Samuel Clemens] => Mark Twain
[Caryn Johnson] => Whoopi Goldberg
)
)
PHP å°ææ°æ®æ¾å ¥å¯ä»¥è½»æ¾è§£æçå¤ç»´æ°ç»ä¸ã
å¯¹äº PHP æ件å¤çæ¥è¯´ï¼è¿åªæ¯å°å±±ä¸è§ãè¯¸å¦ tidy_parse_file å xml_parse ä¹ç±»çæ´å¤æçå½æ°å¯ä»¥åå«å¸®å©æ¨å¤ç HTML å XML ææ¡£ãæå ³è¿äºç¹æ®å½æ°ç使ç¨ç»èï¼è¯·åé åèèµæãå¦ææ¨è¦å¤çé£äºç±»åçæ件ï¼åé£äºåèèµæå¼å¾ä¸çï¼ä½ä¸å¿ è¿åº¦èèæ¬æä¸è°å°çæ¯ç§å¯è½éå°çæ件类åï¼ä¸é¢æ¯ä¸äºç¨äºå¤çå°ç®å为æ¢ä»ç»çå½æ°çå¾å¥½çéç¨è§åã
å页é¦
æä½³å®è·µ
ç»ä¸è¦åå®ç¨åºä¸çä¸åé½å°æ计åè¿è¡ãä¾å¦ï¼å¦ææ¨è¦æ¥æ¾çæ件已被移å¨è¯¥å½å¦ä½ï¼å¦ææé已被æ¹åèæ æ³è¯»åå ¶å 容åå½å¦ä½ï¼æ¨å¯ä»¥éè¿ä½¿ç¨ file_exists å is_readable é¢å æ£æ¥è¿äºé®é¢ã
æ¸ å 7. ä½¿ç¨ file_exists å is_readable
$filename = "myfile";
if (file_exists($filename) && is_readable ($filename)) {
$fh = fopen($filename, "r");
# Processing
fclose($fh);
}
ä½æ¯ï¼å¨å®è·µä¸ï¼ç¨è¿æ ·ç代ç å¯è½å¤ªç¹çäºãå¤ç fopen çè¿åå¼æ´ç®å并ä¸æ´åç¡®ãif ($fh = fopen($filename, "r")) {
# Processing
fclose($fh);
}
ç±äºå¤±è´¥æ¶ fopen å°è¿å Falseï¼è¿å°ç¡®ä¿ä» å½æ件æåæå¼åææ§è¡æ件å¤çãå½ç¶ï¼å¦ææ件ä¸åå¨æè ä¸å¯è¯»ï¼æ¨å¯ä»¥ææä¸ä¸ªè´è¿åå¼ãè¿å°ä½¿è¿ä¸ªæ£æ¥å¯ä»¥æ£æ¥ææå¯è½éå°çé®é¢ãæ¤å¤ï¼å¦ææå¼å¤±è´¥ï¼å¯ä»¥éåºç¨åºæ让ç¨åºæ¾ç¤ºé误æ¶æ¯ã
å¦ fopen å½æ°ä¸æ ·ï¼file_get_contentsãfile å readfile å½æ°é½å¨æå¼å¤±è´¥æå¤çæ件失败æ¶è¿å Falseãfgetsãfgetssãfreadãfscanf å fclose å½æ°å¨åºéæ¶ä¹è¿å Falseãå½ç¶ï¼é¤ fclose 以å¤ï¼æ¨å¯è½å·²ç»å¯¹è¿äºå½æ°çè¿åå¼é½è¿è¡äºå¤çãä½¿ç¨ fclose æ¶ï¼å³ä½¿æ件å¤çæªæ£å¸¸å ³éï¼ä¹ä¸ä¼æ§è¡ä»ä¹æä½ï¼å æ¤é常ä¸å¿ æ£æ¥ fclose çè¿åå¼ã
å页é¦
ç±æ¨æ¥éæ©
PHP ä¸ç¼ºè¯»åå解ææ件çæææ¹æ³ãè¯¸å¦ fread ä¹ç±»çå ¸åå½æ°å¯è½å¨å¤§å¤æ°æ¶åé½æ¯æä½³çéæ©ï¼æè å½ readfile å好è½æ»¡è¶³ä»»å¡éè¦æ¶ï¼æ¨å¯è½ä¼åç°èªå·±æ´ä¸º readfile çç®åæå¸å¼ãå®å®é ä¸åå³äºæè¦å®æçæä½ã
å¦æè¦å¤ç大éæ°æ®ï¼fscanf å°è½è¯æèªå·±çä»·å¼å¹¶æ¯ä½¿ç¨ file é带 split å sprintf å½ä»¤æ´ææçãç¸åï¼å¦æè¦åæ¾åªåäºå°è®¸ä¿®æ¹ç大éææ¬ï¼åä½¿ç¨ fileãfile_get_contents æ readfile å¯è½æ´åéãä½¿ç¨ PHP è¿è¡ç¼åæè å建æå®ç代çæå¡å¨æ¶å¯è½å°±å±äºè¿ç§æ åµã
PHP ç»æ¨æä¾äºå¤§éå¤çæ件çå·¥å ·ãæ·±å ¥äºè§£è¿äºå·¥å ·å¹¶äºè§£åªäºå·¥å ·æéåäºè¦å¤çç项ç®ãæ¨å·²æ¥æå¾å¤çéæ©ï¼å æ¤å¥½å¥½å°å©ç¨å®ä»¬äº«åä½¿ç¨ PHP å¤çæ件çä¹è¶£ã