20) {
$firstLine = substr($firstLine, 0, 19);
} else {
str_pad($firstLine, 20);
}
$msg = $firstLine;
if(isset($_GET['secondLine'])) {
$secondLine = $_GET['secondLine'];
$len = strlen($secondLine);
if($len > 20) {
$secondLine = substr($secondLine, 0, 19);
}
$msg .= $secondLine;
}
$msg = preg_replace("/[^A-Za-z0-9?![:space:]]/","",$msg); // strip any ASCII commands (eg newlines because they will break the command and print a page) use this if accepting user input.
$msg = substr($msg,0,40); // (optional) truncate message to 40 characters (2 lines)
$printerIP = '127.0.0.1'; // IPV4 (a.b.c.d) obviously change to your printer IP
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_connect($socket,$printerIP,9100) or die("Could not connect to printer.");
$data = chr(27) . "%-12345X@PJL JOB" . chr(13) . chr(10) .
"@PJL RDYMSG DISPLAY=\"$msg\"" . chr(13) . chr(10) .
"@PJL EOJ" . chr(13) . chr(10) .
chr(27) . "%-12345X";
socket_write($socket, $data) or die("Could not write to printer. Check connections.");
echo "Printer status set to:
" . $firstLine . "
" . $secondLine . "
";
}
?>