Answer the question
In order to leave comments, you need to log in
Decode field value in hex format in MySQL
Good morning.
Mysql has an ip field, type char(8), encoding cp1251_bin. IP addresses are stored in this format - d4e82335 .
Question - how to decode an ip address into a normal form in php or directly in a mysql query?
Answer the question
In order to leave comments, you need to log in
in php
$hex='d4e82335';
for($i=0;$i<7;$i=$i+2){
$dec[$i]=hexdec(substr($hex,$i,2));
}
$dec="$dec[0].$dec[2].$dec[4].$dec[6]";
echo($dec);
I see that a solution has been found for MySQL, but I will still offer it in PHP, otherwise terrible bicycles have appeared here.
$str = 'd4e82335';
echo long2ip(hexdec($str)); //212.232.35.53
>Maybe this is the hex spelling of the IP address 212.232.35.53
if so, then here is the function prototype in php:
int hexdec(string hex_string)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question