Kajkac / ZTE-MC-Home-assistant

ZTE MC801A, MC888, MC889 Home assistant addon
32 stars 8 forks source link

How to convert this function in php? #17

Open vihatsoft opened 5 months ago

vihatsoft commented 5 months ago

hi, can some one help me for convert bellow python function in php and that also work with none English characters sms.

  def hex2utf(string):
            length = len(string) // 4
            result = ''
            for i in range(length):
                result += chr(int(string[i*4:i*4+4], 16))
            return result

when i try bellow php function but show unsupported characters � � � � � � when sms in none English characters.

function hexToStr($hex){
    $string='';
    for ($i=0; $i < strlen($hex)-1; $i+=2){
        $string .= chr(hexdec(($hex[$i].$hex[$i+1])));
    }
    return $string;
}

Thank you,

ngarafol commented 5 months ago

Not a php guy, but chatgpt claims this is the php equivalent :)

function hex2utf($string) {
    $length = strlen($string) / 4;
    $result = '';
    for ($i = 0; $i < $length; $i++) {
        $result .= chr(hexdec(substr($string, $i * 4, 4)));
    }
    return $result;
}
vihatsoft commented 5 months ago

okay, thank you

ngarafol commented 1 month ago

@vihatsoft Did it work? If yes, can you close the issue please?

vihatsoft commented 1 month ago

@vihatsoft Did it work? If yes, can you close the issue please?

when i try show unsupported characters � � � � � � when sms in none English characters. after this problem i use bellow python script, and working fine for none English SMS characters. https://github.com/Kajkac/ZTE-MC-Home-assistant/blob/master/python_scripts%2Fzte_tool.py