Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用php在网络上读取txt文件_Php_File Get Contents_Txt - Fatal编程技术网

用php在网络上读取txt文件

用php在网络上读取txt文件,php,file-get-contents,txt,Php,File Get Contents,Txt,我需要用PHP读取和解析网络上的txt文件 “警告:文件获取内容(文件//10.0.2.129/lims/lims.txt):无法 open stream:中没有此类文件或目录 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

我需要用PHP读取和解析网络上的
txt
文件

“警告:文件获取内容(文件//10.0.2.129/lims/lims.txt):无法 open stream:中没有此类文件或目录 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));
?>

尝试使用文件获取内容('./lims/lims.txt'); 但是,请确保根据调用此函数的位置选择正确的路径。

试试这个

\\\\10.0.2.129\\lims\\lims.txt

文件\u获取\u内容
可以与本地文件一起使用,也可以通过协议使用(此处列出:)

在您的示例中,您遗漏了“:”在“file”和“/”之间。而且,基于IP外观,您的文件位于共享磁盘上,因此您必须在之前添加网络前缀
\\

所以它应该是
file\u get\u contents('file://\\\\10.0.2.129/lims/lims.txt')

由于“file://”是默认协议,您可以将其删除为仅保留
文件获取内容('\\\\10.0.2.129/lims/lims.txt')
文件//
不是有效协议,因此如何启动,使用有效协议您缺少冒号:请尝试file://查看有效协议问题是从网络读取文件,与脚本不在同一目录警告:file\u get\u contents(\\10.0.2.129\lims\lims.txt):无法打开流:在第2行的C:\AppServ\www\mail\index.php中被拒绝权限我认为您需要先允许权限我不知道如何让我们使用其他内容代替file\u get\u contents来读取文件?是的,看看fopen、fread和fclose组合:,第一个例子