SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | ||
| 3 | $msg = "Your first line "; // first line (20 chars max) | |
| 4 | $msg .= " "; // second line, comment this out if your display is one line only | |
| 5 | ||
| 6 | if(isset($_GET['firstLine'])) {
| |
| 7 | $firstLine = $_GET['firstLine']; | |
| 8 | $len = strlen($firstLine); | |
| 9 | if($len > 20) {
| |
| 10 | $firstLine = substr($firstLine, 0, 19); | |
| 11 | } else {
| |
| 12 | - | for ($i=$len; $i <= 20; $i++) {
|
| 12 | + | str_pad($firstLine, 20); |
| 13 | - | $firstLine .= " "; |
| 13 | + | |
| 14 | $msg = $firstLine; | |
| 15 | ||
| 16 | if(isset($_GET['secondLine'])) {
| |
| 17 | $secondLine = $_GET['secondLine']; | |
| 18 | $len = strlen($secondLine); | |
| 19 | if($len > 20) {
| |
| 20 | $secondLine = substr($secondLine, 0, 19); | |
| 21 | } | |
| 22 | $msg .= $secondLine; | |
| 23 | } | |
| 24 | ||
| 25 | $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.
| |
| 26 | $msg = substr($msg,0,40); // (optional) truncate message to 40 characters (2 lines) | |
| 27 | ||
| 28 | $printerIP = '127.0.0.1'; // IPV4 (a.b.c.d) obviously change to your printer IP | |
| 29 | ||
| 30 | $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); | |
| 31 | socket_connect($socket,$printerIP,9100) or die("Could not connect to printer.");
| |
| 32 | $data = chr(27) . "%-12345X@PJL JOB" . chr(13) . chr(10) . | |
| 33 | "@PJL RDYMSG DISPLAY=\"$msg\"" . chr(13) . chr(10) . | |
| 34 | "@PJL EOJ" . chr(13) . chr(10) . | |
| 35 | chr(27) . "%-12345X"; | |
| 36 | socket_write($socket, $data) or die("Could not write to printer. Check connections.");
| |
| 37 | ||
| 38 | echo "<strong>Printer status set to:<br>" . $firstLine . "<br>" . $secondLine . "</strong><br>"; | |
| 39 | } | |
| 40 | ||
| 41 | ?> | |
| 42 | <!doctype html> | |
| 43 | <html lang="en"> | |
| 44 | <head> | |
| 45 | <meta charset="utf-8"> | |
| 46 | <title>Set HP Printer LCD Status</title> | |
| 47 | </head> | |
| 48 | <body> | |
| 49 | <form method="GET"> | |
| 50 | <table> | |
| 51 | <tr> | |
| 52 | <td><label for="firstLine">First line (20 chars max):</label></td> | |
| 53 | <td><input type="text" id="firstLie" name="firstLine" size="20"></td> | |
| 54 | </tr> | |
| 55 | <tr> | |
| 56 | <td><label for="secondLine">Second line (20 chars max):</label></td> | |
| 57 | <td><input type="text" id="secondLie" name="secondLine" size="20"></td> | |
| 58 | </tr> | |
| 59 | <tr> | |
| 60 | <td></td> | |
| 61 | <td><input type="submit" value="Submit"></td> | |
| 62 | </tr> | |
| 63 | </form> | |
| 64 | </body> | |
| 65 | </html> |