I have some code that's taking over 3 seconds to complete. I'm just wondering if there's a faster way to do this.
I have a string with anywhere from 10 to 70 rows of data.
I break it up into an array and then loop through the array to find specific patterns.
$this->_data = str_replace(chr(27)," ",$this->_data,$count);//strip out esc character
$this->_data = explode("\r\n", $this->_data);
$detailsArray = array();
foreach ($this->_data as $details) {
$pattern = '/(\s+)([0-9a-z]*)(\s+)(100\/1000T|10|1000SX|\s+)(\s*)(\|)(\s+)(\w+)(\s+)(\w+)(\s+)(\w+)(\s+)(1000FDx|10HDx|100HDx|10FDx|100FDx|\s+)(\s*)(\w+)(\s*)(\w+|\s+)(\s*)(0)/i';
if (preg_match($pattern, $details, $matches)) {
array_push($detailsArray, array(
'Port' => $matches[2],
'Type' => $matches[4],
'Alert' => $matches[8],
'Enabled' => $matches[10],
'Status' => $matches[12],
'Mode' => $matches[14],
'MDIMode' => $matches[16],
'FlowCtrl' => $matches[18],
'BcastLimit' => $matches[20]));
}//end if
}//end for
$this->_data = $detailsArray;
Just wondering if you think there's a way to make it more efficient.
Thanks.