如何解析php中固定宽度的列文本? [英] How to parse fixed width column text in php?

查看:26
本文介绍了如何解析php中固定宽度的列文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在php中解析并显示下面的文本并在hmtl中输出?

How to parse and display below text in php and output it in hmtl?

我需要的是如何处理分隔列的空间的提示.空格数不是固定的,所以我不能使用 explode(" ",$string); 而且我不确定下面输出的结构是否真的有固定宽度的列.我想让解析函数通用.

What I need is a hint how to approach the spaces that separates the columns. The number of spaces is not fixed so I cannot use explode(" ",$string); And also I am not sure if the structure of below output has really fixed width columns. I want to make the parsing function generic.

输出来自db2 list applications

Auth Id  Application    Appl.      Application Id                                                 DB       # of
         Name           Handle                                                                    Name    Agents
-------- -------------- ---------- -------------------------------------------------------------- -------- -----
DB2INST1 db2jcc_applica 11446      10.0.0.209.51406.120606004531                                  WEI      1    
DB2INST1 db2jcc_applica 11448      10.0.0.209.51407.120606004536                                  WEI      1    
DB2INST1 db2jcc_applica 13762      10.0.0.206.57473.120606024909                                  DOM_BUGS 1    
ADMIN    db2jcc_applica 15220      10.0.0.210.52248.120606045402                                  RATIONAL 1    
DB2INST1 php-fpm: pool  16546      127.0.0.2.35530.120606065726                                   KON      1    
DB2INST1 db2jcc_applica 16547      10.0.0.202.52042.120606065813                                  KON      1 

推荐答案

您可以preg_split 按空格

$words = preg_split("/[s]+/", $input);

//if your lines seperated by `
` new line you could:
$inputArr = preg_split("/R+/", $input);
foreach($inputArr as $value) {
   $out = preg_split("/s+/", $value);
   var_dump($out);
}

Thanks

这篇关于如何解析php中固定宽度的列文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆