-1

I need to read and parse the txt file on the network with PHP.

"Warning: file_get_contents(file//10.0.2.129/lims/lims.txt): failed to open stream: No such file or directory in C:\AppServ\www\mail\index.php on line 2"

This way I get the error message.

<?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));
?>
jrswgtr
  • 2,287
  • 8
  • 23
  • 49
Sefa Kuru
  • 13
  • 6

3 Answers3

0

Try this

\\\\10.0.2.129\\lims\\lims.txt
Jerson
  • 1,700
  • 2
  • 10
  • 14
0

file_get_contents can be used with local files or through protocols (listed here : https://www.php.net/manual/wrappers.php)

In your example, you missed the ":" between "file" and "//". And, based on IP looking, your file is on a shared disk, so you must add the network prefix \\ before.

So it should be file_get_contents('file://\\\\10.0.2.129/lims/lims.txt'). Since "file://" is the default protocol, you can remove it an only keep file_get_contents('\\\\10.0.2.129/lims/lims.txt')

darkelfe
  • 35
  • 1
  • 8
-1

try using file_get_contents('./lims/lims.txt'); but make sure to choose the right path depending the location you are calling this function from.