Hướng dẫn convert text file to array php - chuyển đổi tệp văn bản thành mảng php

Tôi đã tạo một tệp có tên ________ 5:-

 0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
 1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
 2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
 3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
 4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
 5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        

Bây giờ tôi đã áp dụng mã dưới đây:-

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);

Và đầu ra là:-

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)

Bây giờ một cách giải quyết để không cần thay đổi bất cứ điều gì trong tệp văn bản của bạn được đưa ra dưới đây (mã hoàn chỉnh):-

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);

Lưu ý:- Nó sẽ cung cấp cho bạn đầu ra mong muốn chính xác những gì bạn đã hiển thị cho chúng tôi (tôi đã kiểm tra nó ở đầu địa phương của tôi)

Những gì bạn đã hỏi trong bình luận cho điều đó như dưới đây:-

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);

Làm thế nào để đọc một tệp vào một mảng trong PHP?

Php $ file = fopen ("thành viên.txt", "r"); while (! feof ($ file)) {$ line_of_text = fgets ($ file); $ thành viên = Explode ('\ n', $ line_of_text); fclose ($ file); ?> Có gì được lưu trữ trong mảng với mã của bạn không?Reads entire file into an array

Hàm nào đọc toàn bộ tệp vào một mảng?

* File_Get_Contents - Đọc toàn bộ tệp thành một chuỗi. * Tệp - Đọc toàn bộ tệp vào một mảng. * Fopen - Mở tệp hoặc URL.(string $filename, int $flags = 0, ?resource $context = null): array|false

Ghi chú::

Bạn có thể sử dụng file_get_contents () để trả về nội dung của tệp dưới dạng chuỗi.file_get_contents() to return the contents of a file as a string.

Thông số

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
0

Đường dẫn đến tệp.

Mẹo

Một URL có thể được sử dụng như một tên tệp với chức năng này nếu các giấy gói fopen đã được bật. Xem fopen () để biết thêm chi tiết về cách chỉ định tên tệp. Xem các giao thức và trình bao bọc được hỗ trợ để biết các liên kết đến thông tin về những khả năng mà các trình bao bọc khác nhau có, ghi chú về việc sử dụng của chúng và thông tin về bất kỳ biến được xác định trước mà họ có thể cung cấp.fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
1

Tham số tùy chọn

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
1 có thể là một hoặc nhiều hơn, các hằng số sau:

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
3 Tìm kiếm tệp trong bao gồm_path.
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
4 Bỏ qua dòng mới ở cuối mỗi phần tử mảng
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
5 Bỏ qua các dòng trống
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
6
Search for the file in the include_path.
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
4
Omit newline at the end of each array element
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
5
Skip empty lines
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
6

Một tài nguyên luồng ngữ cảnh.resource.

Trả về giá trị

Trả về tệp trong một mảng. Mỗi phần tử của mảng tương ứng với một dòng trong tệp, với dòng mới vẫn được đính kèm. Sau khi thất bại, File () trả về

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
7.file() returns
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
7
.

Ghi chú::

Mỗi dòng trong mảng kết quả sẽ bao gồm kết thúc dòng, trừ khi

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
4 được sử dụng.
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
4
is used.

Lưu ý: Nếu PHP không nhận ra đúng các kết thúc dòng khi đọc các tệp hoặc trên hoặc được tạo bởi máy tính Macintosh, hãy bật tùy chọn cấu hình thời gian chạy Auto_Detect_Line_endings có thể giúp giải quyết vấn đề.: If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem.

Errors/Exceptions

Phát ra lỗi cấp

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
9 nếu tệp không tồn tại.
<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
9
level error if the file does not exist.

Ví dụ

Ví dụ: Tệp 1 () Ví dụfile() example

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
0

Ghi chú

Cảnh báo

Khi sử dụng SSL, Microsoft IIS sẽ vi phạm giao thức bằng cách đóng kết nối mà không gửi chỉ báo

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
1. PHP sẽ báo cáo đây là "SSL: Lỗi giao thức gây tử vong" khi bạn đạt đến cuối dữ liệu. Để làm việc xung quanh điều này, giá trị của error_Reporting nên được hạ xuống mức không bao gồm các cảnh báo. PHP có thể phát hiện phần mềm máy chủ IIS Buggy khi bạn mở luồng bằng trình bao bọc
Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
2 và sẽ triệt tiêu cảnh báo. Khi sử dụng fsockopen () để tạo ổ cắm
Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
3, nhà phát triển có trách nhiệm phát hiện và ngăn chặn cảnh báo này.fsockopen() to create an
Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
3 socket, the developer is responsible for detecting and suppressing this warning.

Xem thêm

  • file_get_contents () - Đọc toàn bộ tệp thành một chuỗi
  • readfile () - xuất ra một tệp
  • fopen () - Mở tệp hoặc URL
  • fsockopen () - Mở Internet hoặc kết nối ổ cắm tên miền UNIX
  • popen () - Mở con trỏ tệp quy trình
  • Bao gồm - bao gồm
  • stream_context_create () - Tạo ngữ cảnh Stream

Martin K.

8 năm trước

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
4

renanlazarotto tại gmail dot com ¶

1 năm trước

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
5

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
6

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
7

Bingo tại Dingo Dot Com ¶

9 năm trước

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
8

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
9

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
7

d Basin ¶

13 năm trước

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
1

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
2

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
3

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
4

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
5

Twichi tại Web Dot de ¶

11 năm trước

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
6

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
7

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
8

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
9

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);
0

Sheldon tại siêu liên kết DOT com ¶

3 năm trước

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);
1

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);
2

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);
3

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);
4

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
7

Justin tại Visunet Dot tức là ¶

19 năm trước

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);
6

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);
7

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
$indexed_array = Array('number','flag','name','service','mac','IP','uptime');

foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = array_combine($indexed_array,$parts);
}

echo "<pre/>";print_r($new_array);
8

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
7

Đảo ngược: MOC DOT LIAMG tại Senroc Dot Werdna ¶

15 năm trước

myfile.txt0

myfile.txt1

myfile.txt2

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
7

Vbchris tại Gmail Dot Com ¶

14 năm trước

myfile.txt4

Jon+Spamcheck tại phpsitesolutions dot com ¶

14 năm trước

myfile.txt5

myfile.txt6

myfile.txt7

myfile.txt8

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
7

Jon+Spamcheck tại phpsitesolutions dot com ¶

8 năm trước

$filename0

$filename1

$filename2

$filename3

$filename4

<?php
$array = explode("\n", file_get_contents('myfile.txt'));

echo "<pre/>";print_r($array);
$new_array = array();
foreach($array as $key =>&$arr){

    if ($arr[3] !=='R'){

        $arr[3] ="_";
    }
    $parts = preg_split('/\s+/', trim($arr));
    if($parts[1] == '_'){
        $parts[1] = '';
    }
    $new_array[$key] = $parts;
}

echo "<pre/>";print_r($new_array);
3

$filename6

$filename7

renanlazarotto tại gmail dot com ¶

1 năm trước

$filename8

$filename9

$flags0

$flags1

$flags2

Array
(
    [0] =>  0   hbhenet      pppoe   D4:CA:6D:F1:5D:5A 10.23.0.254     8h2m36s            
    [1] =>  1 R moh@hj       pppoe   00:27:22:16:3B:F2 10.17.0.253     8h2m36s            
    [2] =>  2 R omarmool@dr  pppoe   68:72:51:3A:53:1B 10.17.0.251     8h2m36s            
    [3] =>  3 R admin@khr2   pppoe   24:A4:3C:9F:83:10 10.17.0.252     8h2m36s            
    [4] =>  4 R   pppoe   24:A4:3C:E6:DD:3E 10.17.0.250     8h2m36s            
    [5] =>  5 R   pppoe   44:D9:E7:DA:32:95 10.16.0.246     8h2m36s        
)
7

Bingo tại Dingo Dot Com ¶

8 năm trước

$flags4

$flags5

$flags6

$flags7

renanlazarotto tại gmail dot com ¶

15 năm trước

$flags8

$flags9

Vbchris tại Gmail Dot Com ¶

Làm thế nào để đọc một tệp vào một mảng trong PHP?

Php $ file = fopen ("thành viên.txt", "r");while (! feof ($ file)) {$ line_of_text = fgets ($ file);$ thành viên = Explode ('\ n', $ line_of_text);fclose ($ file);?> Có gì được lưu trữ trong mảng với mã của bạn không?$file = fopen("members. txt", "r"); while (! feof($file)) { $line_of_text = fgets($file); $members = explode('\n', $line_of_text); fclose($file); ?> Is anything stored in the array with your code as it is?

Hàm nào đọc toàn bộ tệp vào một mảng?

* File_Get_Contents - Đọc toàn bộ tệp thành một chuỗi.* Tệp - Đọc toàn bộ tệp vào một mảng.* Fopen - Mở tệp hoặc URL.* file — Reads entire file into an array. * fopen — Opens file or URL.

Khi xử lý một tệp trong PHP, chúng ta sử dụng phương pháp nào để mở và đóng các tệp đúng cách?

Một phương thức tốt hơn để mở các tệp là với hàm fopen ().Hàm này cung cấp cho bạn nhiều tùy chọn hơn hàm readfile ().... Thí dụ..

Chức năng nào được sử dụng để đọc một tệp hiện có trong PHP?

Php Read Tệp - fread () Hàm fread () được sử dụng để đọc dữ liệu của tệp.