' => GS."B".chr(1), '' => GS."B".chr(0), '' => ESC."\x2d".chr(1).FS."\x2d".chr(1), '' => ESC."\x2d".chr(2).FS."\x2d".chr(2), '' => ESC."\x2d".chr(0).FS."\x2d".chr(0), '' => GS."!".chr(17), '' => GS."!".chr(00), '' => ESC."E".chr(1), '' => ESC."E".chr(0), '' => ESC."a".chr(0), '
' => ESC."a".chr(1), '' => ESC."a".chr(2), '' => ESC."@".FS."C".chr(1), '' => str_repeat('─', 24), '<2bline>' => str_repeat('━', 24), '' => GS."!".chr(01), '' => GS."!".chr(16), '' => GS."V\x41".chr(3), '' => '', '' => ESC."\x4d".chr(0), '' => ESC."\x4d".chr(1), '' => ESC."\x4d".chr(2), '' => '', '' => '', '' => '', '' => '', '' => '', '' => '', '' => '', '' => '', ); // 文字列の長さを返す関数 function mb_text_byte($text){ mb_language("Japanese"); mb_internal_encoding("UTF-8"); return(strlen(mb_convert_encoding($text, 'SJIS', 'UTF-8'))); } // (本筋) ESCPOSに変換するのみ function conv2escpos($text = '', $multi = 1, $cut = true){ mb_language("Japanese"); mb_internal_encoding("UTF-8"); global $experts; // BEGIN 前処理 $postedText = str_replace(array("\r\n", "\r"), array("\n", "\n"), $text); $postedTextArray = explode("\n", ''.$postedText); $postedTextArrayOrig = explode("\n", $postedText); $postedTextNewArray = array(); // があるかどうかで処理 foreach($postedTextArray as $v){ $counted = count(explode('', $v)); if($counted == 2){ $tmpArray = explode('', $v); $tmpArrayStrippedLen = array(); foreach($tmpArray as $tA){ $tmpArrayStrippedLen[] = mb_text_byte(strip_tags($tA)); } $postedTextNewArray[] = $tmpArray[0].str_repeat(" ", (48 - array_sum($tmpArrayStrippedLen))).$tmpArray[1]; }else{ $postedTextNewArray[] = $v; } } // があるかどうかで処理 $postedTextArray = $postedTextNewArray; $postedTextNewArray = array(); foreach($postedTextArray as $v){ $counted = count(explode('', $v)); if($counted == 2){ $tmpArray = explode('', $v); $tmpArrayStrippedLen = array(); foreach($tmpArray as $tA){ $tmpArrayStrippedLen[] = mb_text_byte(strip_tags($tA)); } $tmpArrayStrippedLen[] = mb_text_byte(strip_tags($tmpArray[1])); $postedTextNewArray[] = $tmpArray[0].str_repeat(" ", (48 - array_sum($tmpArrayStrippedLen))).$tmpArray[1]; }else{ $postedTextNewArray[] = $v; } } // があるかどうかで処理 $postedTextArray = $postedTextNewArray; $postedTextNewArray = array(); foreach($postedTextArray as $v){ $counted = count(explode('', $v)); if($counted == 2){ $tmpArray = explode('', $v); $tmpArrayStrippedLen = array(); foreach($tmpArray as $tA){ $tmpArrayStrippedLen[] = mb_text_byte(strip_tags($tA)); } $postedTextNewArray[] = $tmpArray[0].str_repeat(" ", (48 - 2*array_sum($tmpArrayStrippedLen))).$tmpArray[1]; }else{ $postedTextNewArray[] = $v; } } // バーコード $postedTextBaredArray = array(); foreach($postedTextNewArray as $v){ $counted = count(explode('', $v)); if($counted > 1){ $prevText = explode('', $v)[0]; $bartext = explode('', explode('', $v)[1])[0]; $nextText = explode('', $v)[1]; $bar = GS."\x48".chr(2); // 可視コードの印字位置の選択(下) $bar .= GS."\x68".chr(80); // バーコードの長さ $bar .= GS."\x77".chr(2); // バーコードの横幅 $bar .= GS."k".chr(73).chr(mb_text_byte($bartext)+2)."\x7B\x42" . $bartext."\x0a"; // 文字数は文字数アクション後の文字から $postedTextBaredArray[] = $prevText.$bar.$nextText."\n".FS."C".chr(1); } else { $postedTextBaredArray[] = $v; } } // バーコード Codebar $postedTextNewArray = $postedTextBaredArray; $postedTextBaredArray = array(); foreach($postedTextNewArray as $v){ $counted = count(explode('', $v)); if($counted > 1){ $prevText = explode('', $v)[0]; $bartext = explode('', explode('', $v)[1])[0]; $nextText = explode('', $v)[1]; $bar = GS."\x48".chr(2); // 可視コードの印字位置の選択(下) $bar .= GS."\x68".chr(80); // バーコードの長さ $bar .= GS."\x77".chr(2); // バーコードの横幅 $bar .= GS."k".chr(6)."A".$bartext."A".NUL; $postedTextBaredArray[] = $prevText.$bar.$nextText."\n".FS."C".chr(1); } else { $postedTextBaredArray[] = $v; } } // QR 新 $tmptext = explode("", implode("\n", $postedTextBaredArray)); if(count($tmptext) == 1){ // そのまま $newText = implode("\n", $postedTextBaredArray); } else { // 該当文字列を変換 $newText = $tmptext[0]; for($i = 1; $i < count($tmptext); $i++){ list($bartext, $nextText) = explode("", $tmptext[$i]); $textCount = mb_text_byte($bartext)+3; $textCountArray = array($textCount % 256, floor($textCount/256)); $bar = GS."(k".chr(3).chr(0).chr(49).chr(67).chr(6); // ユニットの大きさ $bar .= GS."(k".chr(3).chr(0).chr(49).chr(69).chr(7); // エラー訂正 $bar .= GS."(k".chr($textCountArray[0]).chr($textCountArray[1]).chr(49).chr(80).chr(48); // 格納 $bar .= $bartext; $bar .= GS."(k".chr(3).chr(0).chr(49).chr(81).chr(48); // 印字 $newText .= $bar.$nextText."\n".FS."C".chr(1); //結合 } } $postedTextNew = $newText; // PDF417 $tmptext = explode("", $postedTextNew); if(count($tmptext) == 1){ // そのまま $newText = $postedTextNew; } else { // 該当文字列を変換 $newText = $tmptext[0]; for($i = 1; $i < count($tmptext); $i++){ list($bartext, $nextText) = explode("", $tmptext[$i]); $textCount = mb_text_byte($bartext)+3; $textCountArray = array($textCount % 256, floor($textCount/256)); // $bar = GS."(k".chr(3).chr(0).chr(48).chr(65).chr(30); // 桁数 // $bar = GS."(k".chr(3).chr(0).chr(48).chr(66).chr(8); // 段数 $bar = GS."(k".chr(3).chr(0).chr(48).chr(67).chr(5); // ユニット幅の大きさ $bar = GS."(k".chr(3).chr(0).chr(48).chr(68).chr(3); // ユニット高の大きさ // $bar .= GS."(k".chr(3).chr(0).chr(49).chr(69).chr(7); // エラー訂正 // $bar .= GS."(k".chr(3).chr(0).chr(48).chr(70).chr(1); // オプション有効 $bar .= GS."(k".chr($textCountArray[0]).chr($textCountArray[1]).chr(48).chr(80).chr(48); // 格納 $bar .= $bartext; $bar .= GS."(k".chr(3).chr(0).chr(48).chr(81).chr(48); // 印字 $newText .= $bar.$nextText."\n".FS."C".chr(1); //結合 } } $postedTextNew = $newText; // $postedTextNew = implode("\n", $postedTextNewArray); // END 前処理 /* ASCII constants */ $out = FS."C".chr(1); if(ctype_digit(@$multi)){ $multinum = max(((int) $multi), 1); } else { $multinum = 1; } $postedTextNew = implode(PHP_EOL.''.FS."C".chr(1), array_fill(0, $multinum, $postedTextNew)); $out .= mb_convert_encoding(str_replace(array_keys($experts) , array_values($experts), $postedTextNew), "SJIS"); if($cut == true) { // Cut & close $out .= ESC."d".chr(1); // Blank line $out .= GS."V\x41".chr(3); // Cut } return $out; } // 引数のファイルを読み込んで変換して印刷して削除 $content = file_get_contents($argv[1]); $out = conv2escpos($content); file_put_contents($escpos_tmppath, $out); exec("cat ".$escpos_tmppath."| lpr -P ".$printer);