Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert this function in php? #17

Open
vihatsoft opened this issue Feb 27, 2024 · 4 comments
Open

How to convert this function in php? #17

vihatsoft opened this issue Feb 27, 2024 · 4 comments

Comments

@vihatsoft
Copy link

vihatsoft commented Feb 27, 2024

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
Copy link
Collaborator

ngarafol commented Mar 8, 2024

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
Copy link
Author

okay, thank you

@ngarafol
Copy link
Collaborator

ngarafol commented Jul 1, 2024

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

@vihatsoft
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants