Hex2bin convert to txt

Hello, i try to convert hex to text

<?php
$ip='192.168.0.5';
$ro='public';
$session = new SNMP(SNMP::VERSION_2C, $ip, $ro);
$ONUsoft = $session->walk("1.3.6.1.4.1.3320.101.10.1.1.5", TRUE);
$hex = hex2bin($ONUsoft);
echo $hex;

result is array array

when i add
var_dump($hex);

result is :
NULL NULL NULL

when i add
var_dump($ONUsoft);

result is :

array(64) { [11]=> string(60) "Hex-STRING: 31 30 2E 30 2E 32 36 42 2E 35 30 31 00 00 00 00 " [12]=> string(60) "Hex-STRING: 31 30 2E 30 2E 31 36 41 20 31 30 32 33 00 00 00 " [13]=> string(60) "Hex-STRING: 31 30 2E 30 2E 31 37 41 20 31 30 31 37 00 00 00 " [14]=> string(60) "Hex-STRING: 31 30 2E 30 2E 31 37 41 20 31 30 31 37 00 00 00 " [15]=> string(60) "Hex-STRING: 31 30 2E 30 2E 31 36 41 20 31 30 34 37 00 00 00 " [16]=>…

I just wanna get only convert 31 30 2E 30 2E 32 36 42 2E 35 30 31 00 00 00 00 to - > 10.0.26B.501

Just read the manual:

https://www.php.net/manual/en/function.hex2bin.php

hex2bin ( string $data ) : string

The function requires a string - did you give it a string? No, you gave it an array.

How do you get certain data from an array? Read the manual:

https://www.php.net/manual/en/language.types.array.php

Decoding of that hex is fine, you just have to use the entry behind the right key:

<?php

$hex = '31 30 2E 30 2E 32 36 42 2E 35 30 31 00 00 00 00';
$hey = strtr($hex, [' ' => '']);
$bin = hex2bin($hey);

var_dump($hex, $hey, $bin); // string(16) "10.0.26B.501"

Hello “chorn” tnk for answer.
now is problem to get only

31 30 2E 30 2E 32 36 42 2E 35 30 31 00 00 00 00

from

array(64) { [11]=> string(60) "Hex-STRING: 31 30 2E 30 2E 32 36 42 2E 35 30 31 00 00 00 00 " [12]=> string(60) "Hex-STRING: 31 30 2E 30 2E 31 36 41 20 31 30 32 33 00 00 00 " [13]=> string(60) "Hex-STRING: 31 30 2E 30 2E 31 37 41 20 31 30 31 37 00 00 00 " [14]=> string(60) "

I am totally php noob

And what did you find out while practicing the examples from the manual i posted a link to?

Well i change the code

$hex = ($ONUsoft[11]);
$hey = strtr($hex, [‘Hex-STRING:’ => ‘’, ’ ’ => ‘’]);
$bin = hex2bin($hey);

echo $bin ;

now it works the way i want. Тhank you again

Sponsor our Newsletter | Privacy Policy | Terms of Service