Chuyển file

Chuyển File Php ? Thao Tác Với File Trong Php

0 hbhenet pppoe D4:CA:6D:F1:5D:5A 10.23.0.254 8h1m36s 1 R moh

Đang xem: Chuyển file php

ahmed.m pppoe 44:D9:E7:DA:32:95 10.16.0.246 8h1m36s 2)and what i have done in my php is :

$file=”converted.txt”;$fopen = fopen($file, “r”);$fread = fread($fopen,filesize($file));fclose($fopen);$remove = ”
“;$split = explode($remove, $fread);$array<> = NULL;$tab = ” “;foreach ($split as $string){ $row = explode($tab, $string); array_push($array,$row);}echo “”;print_r($array);echo “”;3)the output is like :

Array( <0> => <1> => Array ( <0> => 0 hbhenet pppoe D4:CA:6D:F1:5D:5A 10.23.0.254 8h1m36s )<2> => Array ( <0> => 1 R moh
ahmed.m pppoe 44:D9:E7:DA:32:95 10.16.0.246 8h1m36s ) )4)but what i want is :

Array(

<0> => Array ( <0> => Array ( <0> => 0 <1> => <2> => hbhenet <3> => pppoe <4> => D4:CA:6D:F1:5D:5A <5> => 10.23.0.254 <6> => 8h1m36s ) <1> => Array ( <0> => 1 <1> => R <2> => moh
hj <3> => pppoe <4> => 00:27:22:16:3B:F2 <5> => 10.17.0.253 <6> => 8h1m36s ) <2> => Array ( <0> => 2 <1> => R <2> => omarmool
dr <3> => pppoe <4> => 68:72:51:3A:53:1B <5> => 10.17.0.251 <6> => 8h1m36s ) <3> => Array ( <0> => 3 <1> => R <2> => admin
khr2 <3> => pppoe <4> => 24:A4:3C:9F:83:10 <5> => 10.17.0.252 <6> => 8h1m36s ) <4> => Array ( <0> => 4 <1> => R <2> => yas
ahmed.m <3> => pppoe <4> => 24:A4:3C:E6:DD:3E <5> => 10.17.0.250 <6> => 8h1m36s ) <5> => Array ( <0> => 5 <1> => R <2> => hus

Xem thêm: Lịch Tiêm Chủng Mở Rộng Miễn Phí, Thông Tin Về Thuốc Chủng Ngừa Covid

ahmed.m <3> => pppoe <4> => 44:D9:E7:DA:32:95 <5> => 10.16.0.246 <6> => 8h1m36s ) ) )any idea?thanks in advance.

*

*

I have created a file with name myfile.txt:-

0 hbhenet pppoe D4:CA:6D:F1:5D:5A 10.23.0.254 8h1m36s 1 R moh
ahmed.m pppoe 44:D9:E7:DA:32:95 10.16.0.246 8h1m36s Now i have applied below code:-

“;print_r($array);And output is :-

Array( <0> => 0 hbhenet pppoe D4:CA:6D:F1:5D:5A 10.23.0.254 8h1m36s <1> => 1 R moh

Xem thêm: mortal kombat game do.w.n.lo.ad

ahmed.m pppoe 44:D9:E7:DA:32:95 10.16.0.246 8h1m36s )Now a workaround so that no need to change anything in your text file is given below (complete code):-

“;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 “”;print_r($new_array);Note:- it will give you exact desired output what you shown to us (I have tested it at my local end)

What you asked in comment for that do like below:-

“;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 “”;print_r($new_array);

Show More

Related Articles

Back to top button
Close