将txt文件读入HTML表格

时间:2016-02-11 15:55:55

标签: html

我必须将txt文件读入HTML表格。 其中有很多字段,但我只想阅读“" value"”字段。

这是我的txt文件:

one=availability:, timestamp=90754, value=no
two=description:, timestamp=074693, value=not sure
three=Name, timestamp=90761, value=yes

一,二,三个值是我的行标题,我希望它显示下面的值。

无论如何使用iframe执行此操作? PHP不适合我。

3 个答案:

答案 0 :(得分:0)

假设值始终是最后一个字段,并且您逐行读取文件,我会使用脏方法:

$value = explode('value=', $line)[1];

答案 1 :(得分:0)

如果所有行都遵循相同的模式,则可以使用:

//$textfilestring = "one=availability:, timestamp=90754, value=no
               //two=description:, timestamp=074693, value=not sure
               //three=Name, timestamp=90761, value=yes";
$textfilestring = file_get_contents("PATH_TO_FILE");
$arraylines = explode("\n", $textfilestring);

for ($i=0;$i<count($arraylines);$i++) {
    $arraylines[$i] = explode("value=", $arraylines[$i]);

}
echo "<pre>";
var_dump($arraylines);
echo "</pre>";

echo $arraylines[0][1] . "<br>";
echo $arraylines[1][1] . "<br>";
echo $arraylines[2][1] . "<br>";

$ arraylines应该是二维的,其中一部分是

one=availability:, timestamp=90754, 

和一个蜜蜂

no

虽未经过测试。

答案 2 :(得分:0)

longwinded方法

conn = psycopg2.connect(database='cpn')
cur = conn.cursor()

location_filter = "SELECT id FROM developers WHERE location = %s"
out_file.write(cur.mogrify(location_filter, (location,)))
相关问题