Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想用php把文本文件放到表中_Php - Fatal编程技术网

我想用php把文本文件放到表中

我想用php把文本文件放到表中,php,Php,我有一个文本文件: [{“标题”:“…”,“书”:[“A”,“B”]}] 我如何使用php阅读它并将其放入表中?执行类似的操作 如果需要读取文本文件,请使用函数 <?php $fh = file_get_contents('text.txt'); $table = json_decode($fh); ?> <table> <thead> <tr> <th>Head 1&l

我有一个文本文件:

[{“标题”:“…”,“书”:[“A”,“B”]}]


我如何使用php阅读它并将其放入表中?

执行类似的操作

如果需要读取文本文件,请使用函数

<?php
$fh     =   file_get_contents('text.txt');
$table  =   json_decode($fh);
?>
<table>
    <thead>
        <tr>
            <th>Head 1</th>
            <th>Head 2</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($table as $val){ ?>
        <tr>
            <td><?php echo $val->title; ?></td>
            <td><?php echo $val->Book[0]; ?></td>

        </tr>
        <?php } ?>
    </tbody>
</table>

总目1
总目2

注意根据需要设置您的表头。

文件获取内容()到目前为止您做了什么?您希望在其中插入数据的表结构是什么?我的表结构:课程、时间、房间、教授、学生人数您是否以json格式获取数据?OP希望从文本文件中读取文本。你的答案没有回答这个问题,它是有效的。除时间[0]外,仅显示WS1。。顺便说一句,非常感谢。我很抱歉。我只是个初学者。我会更加努力。非常感谢。