I have some code that extracts a bunch of data and stores the result into a variable.
When I try to run a reg expression on it, it is unable to find a match. But if I dump the variable to screen by doing an echo statement, and then copy all the data from the screen into a variable and run the regex on the new variable then it is able to find 80+ matches.
Here is the code that I am currently using:
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);
Here’s what the print_r gives in part :(it’s really really long!)
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
Could someone please assist with this issue?
Check your raw data. What you may be copying is slightly different than what is in $data. An example of this might be non-white space characters displaying as white space and then being copied as white space. You might have to dump $data to a file with a binary write and then look at the characters with a hex editor.
I have run into similar problems myself in the past.