【发布时间】:2020-09-24 11:23:36
【问题描述】:
我需要用PHP读取和解析网络上的txt文件。
“警告:file_get_contents(file//10.0.2.129/lims/lims.txt): 失败 打开流:中没有这样的文件或目录 C:\AppServ\www\mail\index.php 在第 2 行"
这样我会收到错误消息。
<?php
$txt_file = file_get_contents('file//10.0.2.129/lims/lims.txt');
function sp($x) {
return preg_split("/\s\s+|\s*\((\d{4}).*\)/", $x,0,PREG_SPLIT_DELIM_CAPTURE);
}
$array = preg_split("/\n/", $txt_file);
$processed = array_map('sp', $array);
print_r(json_encode($processed));
?>
【问题讨论】:
-
file//不是有效协议 -
那我该怎么办
-
首先,使用有效的协议
-
你少了一个冒号:试试 file:// 请参阅php.net/manual/en/wrappers.php 了解有效协议
标签: php file-get-contents txt