Tuesday, August 18, 2015

PHP Convert Text into Unicode hex for Sending SMS

Use below function to convert text into Unicode hex value.

$text = 'अ';

function hex_chars($data){
    $mb_hex = '';
    for($i = 0 ; $i < mb_strlen($data,'UTF-8') ; $i++){
        $c = mb_substr($data,$i,1,'UTF-8');
        $o = unpack('N',mb_convert_encoding($c,'UCS-4BE','UTF-8'));
        $mb_hex .= sprintf('%04X',$o[1]);
    }
    return $mb_hex;

}

echo hex_chars($text);

Total Pageviews