Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Needed Hex2Bin function!

Status
Not open for further replies.
Jun 14, 1999
606
0
0
US
I'm passing some binary informatio from form to form this way:<br><FONT FACE=monospace><br>&lt;?php<br>$arr = array( $data1, $data2, $data3, $data4 )<br>bindata = bin2hex( serialize( $arr ) );<br>?&gt;<br></font><br>then I do in the form:<br><FONT FACE=monospace><br>&lt;input type=hidden name=&quot;bindata&quot; &lt;?php<br>echo &quot;value=\&quot;$bindata\&quot;&gt; ?&gt;<br></font><br>and sending the info.<br><br>Now I want to extract that info in the called form:<br><FONT FACE=monospace><br>&lt;?php<br>&nbsp;&nbsp;if ( isset( $bindata ) ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;$arr = unserialize( <font color=red>hex2bin</font>( $bindata ) );<br>&nbsp;&nbsp;}<br>?&gt;<br></font><br>But the function hex2bin does <font color=red>not</font> exists!<br><br>What can I do?<br>TIA
 
Try the pack(string format,mixed[args]....) function<br><br>This packes given arguments into binary strings according to the format you pass it.<br><br>In this case a format code would be somethign like 'h' (Hex string, low nibble first) or 'H' (Hex string, high nibble first).<br><br>$binarydata = pack(&quot;h&quot;,$hexdata); or<br>$binarydata = pack(&quot;H&quot;,$hexdata);<br><br>Sincerely,<br>Chad.
 
You say I can use:<br><FONT FACE=monospace><br>&lt;?php<br>&nbsp;&nbsp;$bindata = pack( &quot;h*&quot;, serialize( $arr ) );<br>?&gt;<br></font><br>and then<br><FONT FACE=monospace><br>&lt;input type=&quot;hidden&quot; name=&quot;bindata&quot;<br>&lt;?php echo &quot;value=\&quot;.$bindata.&quot;\&quot;&gt;&quot;; ?&gt;<br></font><br><br>Then, in the processing form, I can do:<br><FONT FACE=monospace><br>$arr = unserialize( $unpack( ...something with $bindata... ) )<br></font><br><br>Yes?<br>PS: I don't understand unpack sintax...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top