Skip to content

Instantly share code, notes, and snippets.

@parsibox
Created December 22, 2017 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsibox/614839803472e885e480ee7e1addfc96 to your computer and use it in GitHub Desktop.
Save parsibox/614839803472e885e480ee7e1addfc96 to your computer and use it in GitHub Desktop.
conver mikrotik ssh to array
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