Jump to content

Escaping characters in strings


miseleigh

Recommended Posts

I need to create strings with escape hex numbers - I'm trying to use sockets to write to a device that needs binary values.  If I use a single string like "\x8" it does exactly what I'm looking for, but putting the 8 into a variable and appending them doesn't work properly.  Any tips?

 

$hex1 = "\x8";
socket_write($socket, $hex1);   //this works!

$hex = 8;
$hex2 = "\x".$hex;
socket_write($socket, $hex2);   //this one doesn't, but I need to be able to do this.

 

I've also tried $hex2 = '\x'.$hex and $hex2 = "\x$hex".  Neither worked.  Any help would be awesome.

Link to comment
https://forums.phpfreaks.com/topic/96740-escaping-characters-in-strings/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.