Jump to content

Newline Carriage return in string


Nev

Recommended Posts

Hi all, I hope some one can shed some light for me as how to send a carriage return and newline inside a spring that is being sent to a serialport. then read back to browser. The new lines are not working. I've tried \n \r \r\n <br> PHP_EOL. I can get this to work via the echo command but not when sending the spring via serial port.

 

Thanks in anticipation.

 

$serial->sendMessage("The big Brown Fox jumped over the cold lazey dog") . "<br>";
$serial->sendMessage("Message 2"); 
 
 
// Or to read from 
$read = $serial->readPort(); 
echo $read;
echo "line 1" . "<br>";
echo "line 2" . "<br>";
echo "line 3" . "<br>";
 
I get the Result below.
 
The big Brown Fox jumped over the cold lazey dogMessage 2line 1
line 2
line 3
Link to comment
https://forums.phpfreaks.com/topic/279779-newline-carriage-return-in-string/
Share on other sites


$serial->sendMessage("The big Brown Fox jumped over the cold lazy dog\n") ;
$serial->sendMessage("Message 2\n");

// Or to read from
$read = $serial->readPort();
echo nl2br($read);
echo "line 1" . "<br>";
echo "line 2" . "<br>";
echo "line 3" . "<br>";

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.