我有一些代码可以提取一堆数据并将结果存储到一个变量中。当我尝试对其运行 reg 表达式时,它无法找到匹配项。但是,如果我通过执行 echo 语句将变量转储到屏幕,然后将屏幕中的所有数据复制到一个变量中并在新变量上运行正则表达式,那么它能够找到 80 多个匹配项。
这是我目前正在使用的代码:
require 'HPVC.php';
$hp = new HPVC('10.14.3.23', '123', '');
echo "<br>Attempting connection";
$hp->connect();
echo "<br>connection succeeded";
$data = $hp->showPSAll();
echo "<br>closing connection...";
$hp->close();
echo "<br>connection closed.";
print_r($data);
$pattern = '/(\w+)(\s*)(\w+\/\w+|\s+)(\s*)(\|)(\s*)(\w+)(\s*)(\w+)(\s*)(\w+|\s+)(\s*)(\w+)(\s*)(\w+)(\s*)(\w+)(\s*)(\d)/i';
echo '<br>Number of matches: '.preg_match_all($pattern, $data, $matches, PREG_PATTERN_ORDER);
这是 print_r 给出的部分内容:(它真的很长!)
connection closed. [24;1H [24;16H [24;1H [?25h [24;16H [24;16Hshow inter [24;16H [?25h [24;26H [24;26Hfaces brie [24;26H [?25h [24;36H [24;36Hf [24;36H [?25h [24;37H [24;0H E [24;1H [24;37H [24;1H [2K [24;1H [?25h [24;1H [1;24r [24;1H Status and Counters - Port Status | Intrusion MDI Flow Bcast Port Type | Alert Enabled Status Mode Mode Ctrl Limit ------ --------- + --------- ------- ------ ---------- ---- ---- ----- A1 100/1000T | No Yes Down 1000FDx Auto off 0 A2 100/1000T | No Yes Down 1000FDx Auto off 0 A3 100/1000T | No Yes Down 1000FDx Auto off 0 A4 100/1000T | No Yes Down 1000FDx Auto off 0 A5 100/1000T | No Yes Down 1000FDx Auto off 0 A6 100/1000T | No Yes Down 1000FDx Auto off 0 A7 100/1000T | No Yes Down 1000FDx Auto off 0 A8 100/1000T | No Yes Down 1000FDx Auto off 0 A9 100/1000T | No Yes Down 1000FDx Auto off 0 A10 100/1000T | No Yes Down 1000FDx Auto off 0 A11 100/1000T | No Yes Down 1000FDx Auto off 0 A12 100/1000T | No Yes Down 1000FDx Auto off 0 A13 100/1000T | No Yes Down 1000FDx Auto off 0 A14 100/1000T | No Yes Down 1000FDx Auto off 0 A15 100/1000T | No Yes Down 1000FDx Auto off 0 A16 100/1000T | No Yes Down 1000FDx Auto off 0 A17 100/1000T | No Yes Down 1000FDx Auto off 0 [24;1H [2K [24;1H [1;24r [24;1H A18 100/1000T | No Yes Down 1000FDx Auto off 0 A19 100/1000T | No Yes Down 1000FDx Auto off 0 A20 100/1000T | No Yes Down 1000FDx Auto off 0 A21 100/1000T | No Yes Down 1000FDx Auto off 0 A22 100/1000T | No Yes Down 1000FDx Auto off 0 A23 100/1000T | No Yes Down 1000FDx Auto off 0 A24 100/1000T | No Yes Down 1000FDx Auto off 0 B1 100/1000T | No Yes Down 1000FDx Auto off 0 B2 100/1000T | No Yes Down 1000FDx Auto off 0 B3 100/1000T | No Yes Down 1000FDx Auto off 0 B4 100/1000T | No Yes Down 1000FDx Auto off 0 B5 100/1000T | No Yes Down 1000FDx Auto off 0 B6 100/1000T | No Yes
有人可以帮忙解决这个问题吗?