0

I've searched the web for quite a while now - but nothing usable passed my way :(

Do you know a class/library to decode PDU encoded SMS using PHP?
Doing all the decode by hand using the official documentation scares me a bit.
There seem to be libraries for use in Java (Android) but that does not help.

ajreal
  • 46,720
  • 11
  • 89
  • 119
glutorange
  • 993
  • 1
  • 10
  • 17

3 Answers3

1

Here is a javaScript based GUI. paste your pdu message in middle box in click convert button.

Nasir Iqbal
  • 909
  • 7
  • 24
  • Sorry, I'm searching for a class/library to do the encoding - a GUI for manual encoding does not help. – glutorange Mar 24 '11 at 06:47
  • 1
    library is already there but in javascript. you can save that page, extract javascrtip library and then translate it into PHP. – Nasir Iqbal Mar 26 '11 at 07:21
0

My solution in PHP based on python answer:

<?php
/**
 * Decode 7-bit packed PDU messages
 */
if ( !function_exists( 'hex2bin' ) ) {
    // pre 5.4 fallback
    function hex2bin( $str ) {
        $sbin = "";
        $len = strlen( $str );
        for ( $i = 0; $i < $len; $i += 2 ) {
            $sbin .= pack( "H*", substr( $str, $i, 2 ) );
        }

        return $sbin;
    }
}

function pdu2str($pdu) {
    // chop and store bytes
    $number = 0;
    $bitcount = 0;
    $output = '';
    while (strlen($pdu)>1) {
        $byte = ord(hex2bin(substr($pdu,0,2)));
        $pdu=substr($pdu, 2);
        $number += ($byte << $bitcount);
        $bitcount++ ;
        $output .= chr($number & 0x7F);
        $number >>= 7;
        if (7 == $bitcount) {
            // save extra char
            $output .= chr($number);
            $bitcount = $number = 0;
        }
    }
    return $output;
}

?>
Community
  • 1
  • 1
Martin M
  • 8,430
  • 2
  • 35
  • 53
-2
function DecodePDU($sString = '')
{
    $sString = pack("H*",$sString);
    $sString = mb_convert_encoding($sString,'UTF-8','UCS-2');

    return $sString;
}
Alexander
  • 113
  • 1
  • 3