如何读取文本并获取字符串以转换JSON文件php

I want to get some string in text file and divide then converting to JSON file this is my text file, data.txt

"5 minute input rate 134000 bits/sec, 164 packets/sec

5 minute output rate 1320000 bits/sec, 150 packets/sec"

I want get a string to array and make a JSON file maybe like this:

$time= "5 minute "
$input= "input rate 134000 bits/sec"
$output= "output rate 1320000 bits/sec"
$array[koneksi]= json_decode('[.".$time.":".$input.]');

this is my code in PHP

<?php
$lines = file('var/www/datakom/data.txt');
$title = 'data';
    foreach ($lines as $line_num => $line) {
        echo htmlspecialchars($line) . "<br />
"; }
?>

Please help me. thanks a lot

查看全部
dtby67541
dtby67541
2013/05/23 03:56
  • string
  • json
  • php
  • text
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复