peb_encode

peb_encodeEncode an Erlang message term

Description

resource peb_encode ( string $format_string , array $data )

Encode an Erlang message term.

Parameters

format_string

The format string is composed of one or more directives.

	    ~a - an atom
	    ~s - a string
	    ~b - a binary (contain 0x0 in string)
	    ~i - an integer
	    ~l - a long integer
	    ~u - an unsigned long integer
	    ~f - a float
	    ~d - a double float
	    ~p - an erlang pid

data

The data to send to Erlang node. Initial wrapped with an array, tuple and list data must be wrapped with extra dimension.

Return Values

Returns an Erlang message identifier on success, or FALSE on failure.

Examples

Example #1 peb_encode() example

<?php

$msg 
peb_encode('~a', array(
                             
'hello'
                             
)
                  );
//encode a simple atom

$msg peb_encode('~d', array(
                             
3.1415926
                             
)
                  );
//encode a simple double

$msg peb_encode('[~a]', array(
                                   array(
'hello')
                               )
                  );
//encode a list with only one element

$msg peb_encode('[~a,~d]', array(
                                   array( 
'hello'3.1415926)
                                  )

                  );
//encode a list with two element


$msg peb_encode('{~a}', array(
                                   array( 
'hello')
                                  )
                  );
//encode a tuple with only one element

$msg peb_encode('{~a,~i}', array(
                                   array( 
'hello'1234 )
                                  )
                  );
//encode a list with two element

$msg peb_encode('{~i,{~a,[~s,~d]}}', array(
                                            array( 
1234,
                                                   array(
'pi',
                                                          array(
'is',3.1415926)
                                                        )
                                                 )
                                            )
                 );
//a complex data encode 
?> 

See Also