PHP snmpwalk 中文正常显示方法

<?php

$soft = array();
$result = snmpwalk('127.0.0.1', 'public', '.1.3.6.1.2.1.25.6.3.1', 1000000, 3);
$soft = array_chunk($result, count($result) / 5);
if ($soft != FALSE) {
    if (count($soft) > 0) {
        $data_fetched = 'yes';

        $installed_name = array();
        $installed_type = array();
        $installed_date = array();

        for ($i = 0; $i < count($soft[1]); $i++) {
            $split = explode(':', $soft[1][$i], 2);
            if (strcmp($split[0], 'Hex-STRING') == 0) {
                //		if ($hex) {
                $hex = str_replace(' ', '', $split[1]);
                //$snmp = str_replace(' ', '', $snmp);
                $hex = preg_replace('/[^a-zA-Z0-9]+/', '', $hex);
                $hex = hex2bin($hex);
                //}
                //$snmp = trim($snmp);
                //$output .= hexStr2Ascii($split[1]);
                //$hex = str_replace(' ', '', $split[1]);
                //$hex = str_replace('\r', '', $hex);
                //$hex = str_replace('\n', '', $hex);                            
                //$hexStrArr = explode(' ',$hexStr);
                //$hex='B0D9B6C8CDF8C5CC';
                //$string='';
                //for ($i=0; $i < strlen($hex)-1; $i+=2){
                //    $string .= mb_chr(hexdec($hex[$i].$hex[$i+1]));
                //}
                //$utf = "";
                //foreach($hexStrArr as $octet){
                //$codes = hexdec($octet);
                //if ($char > 0 ) { $asciiOut .= chr($char); }
                //if (is_scalar($codes)) $codes= func_get_args();
                //$str= '';
                // foreach ($codes as $code) $str.= html_entity_decode('&#'.$code.';',ENT_NOQUOTES,'UTF-8');
                //$utf=$utf.$str;
                //}
                //$string='';
                //for ($j=0; $j < strlen($hex)-1; $j+=2){
                //    $string .= mb_chr(hexdec($hex[$j].$hex[$j+1]));
                //}
                //mb_convert_encoding($hex, 'utf-8', 'gbk');
                $installed_name[$i] = $hex;
                //$str = mb_convert_encoding($str, "UTF-7", "EUC-JP");
            } else {
                $data = str_replace('STRING: ', '', $soft[1][$i]);
                $data = str_replace('"', '', $data);
                $installed_name[$i] = $data;
            }
        }
        for ($i = 0; $i < count($soft[3]); $i++) {
            $installed_type[$i] = str_replace('INTEGER: ', '', $soft[3][$i]);
        }
        for ($i = 0; $i < count($soft[4]); $i++) {
            $data = str_replace('STRING: ', '', $soft[4][$i]);
            $installed_date[$i] = $data;
        }

        print_r($installed_name);
        print_r($installed_type);
        print_r($installed_date);
    } else {
        $data_fetched = 'no';
    }
} else {
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值