dtby67541
dtby67541
2013-05-23 03:56

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

  • string
  • json
  • php
  • text

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

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐