我有一个包含一些文本和表格的文本文件。如何识别表格从哪个位置开始???使用PHP。
提前致谢。
在处理文本文件时,测量每一行的大小很重要。例如在你的情况下:
1 037150 ADILIP 135 TAB 1X10 15
2 037121 ARVAST 5 TAB 1X10 15
3 037122 ARVAST 10 TAB 1X15 20
4 037156 ARVAST A 75 TAB 1X10 10
5 037157 ARVAST A 150 TAB 1X10 10
6 037162 ARVAST CF 10 TAB 1X10 10
每行的长度等于 36 并且我假设字段是有意组织的(每个空格或字符都描述了一些东西)。
在了解和分析文件结构后,您可以开始处理它。
$myFile = "file.txt";
$content = file($myFile);
$contentLength = count($content);
之后,我们应该启动“For Loop”并开始从文件导入数据:
for($i = 0; $i < $contentLength; $i++)
{
//and here you start importing field:
//for exaple: as i understand, first field is id
$myId = $content[$i][0];
//and so on, you get each field's value
//and after finishing that maybe input it into database or output in browser, that totally depends on your application
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句