Created
December 22, 2017 20:14
-
-
Save parsibox/614839803472e885e480ee7e1addfc96 to your computer and use it in GitHub Desktop.
conver mikrotik ssh to array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mikrotik_ssh_to_array( $x ){ | |
$out_arr=array(); | |
$out_i=0; | |
$x=str_replace('"' , '' , $x); | |
preg_match_all('/([^:]*?):([^\r\n]*)\r\n?/', $x, $matches); | |
foreach( $matches[1] as $k ){ | |
$k=preg_replace('/\r\n/','' , $k); | |
$k = preg_replace('!\s+!', ' ', $k); | |
$k_arr=explode(' ', $k); | |
foreach( $k_arr as $kk ){ | |
$kk_arr=explode('=', $kk); | |
if( isset( $kk_arr[1])){ | |
$out_arr[$out_i][$kk_arr[0]]=$kk_arr[1]; | |
} | |
} | |
$out_i++; | |
} | |
return $out_arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment