header("Content-type: text/html; charset=utf-8");
class Netprint{
public $host = ‘192.168.2.200‘; //打印机IP
public $port = 9100; //默认端口
public $socket;
function initcon($host, $port = ‘9100‘){//连接打印机
if(!empty($host) && !empty($port)){
$this->host = $host;
$this->port = $port;
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_set_nonblock($socket);
$con = @socket_connect($socket,$this->host,$this->port);
$flag = socket_select($r=array($socket), $w = array($socket), $f = array($socket), 2);
if($flag == ‘1‘){
socket_set_block($socket);
}else{
$flag = socket_select($r=array($socket), $w = array($socket), $f = array($socket), 2);
if($flag == ‘1‘){
socket_set_block($socket);
}else{
return false;
}
}
$this->socket = $socket;
return true;
}else{
return false;
}
}
function initprint(){//初始化打印
if($this->socket){
$sendstr1 = pack("C*", ‘27‘, ‘64‘);
socket_sendto($this->socket,$sendstr1,strlen($sendstr1),0,$this-&g