Search code examples
phpsocketstcpclient

Send whitespace with PHP socket_write


How can I send whitespace with socket_write in php?

When I send "Hello World", the target device recieves "HelloWorld".

$recieved_issi = $_POST['inputISSI'];
$recieved_message = utf8_decode($_POST['inputMessage']); // Hello World

$message = "SendMail=0,$recieved_issi,0,$recieved_message \r";
$len = strlen($message);

$result = socket_write($socket, $message, $len);

Solution

  • Thank you for your Tipps.

    I have to use utf_decode() because the target device uses ANSI and changing the HTML meta tag, does not work correctly.

    I also found the solution. I have to put $recieved_message under double quotes as it is explained in the documentation of lardis mentioned. I have obviously skipped that before.

    $recieved_issi = $_POST['inputISSI'];
    $recieved_message = utf8_decode($_POST['inputMessage']); // Hello World
    
    $message = "SendMail=0,$recieved_issi,0,\"$recieved_message\" \r";
    $len = strlen($message);
    
    $result = socket_write($socket, $message, $len);