实际上我想用下面的代码示例打印内容.
$html拥有我HTML想要打印的所有内容而无需在浏览器中显示视图且在浏览器中没有打印/显示.
我试图找到一个与window.print();工作相同的方法.但需要在PHP.我不想HTML在浏览器中显示所有内容.
有什么方法或伎俩吗?任何建议都可以帮助我.谢谢.
我的示例代码:
$arr = array('one','two','three','four','five');
$html = "<div style='background:red;color:black;'>";
foreach($arr as $value){
$html .= $value.'<br />';
}
$html .= "</div>";
// print code to print $html content as same as JS window.print() works.
Run Code Online (Sandbox Code Playgroud) <html>
<head>
<script type="text/javascript">
function printpage()
{document. getElementById ('print').style.display='none';
window.print()
}
</script>
</head>
<body>
<td align="center">
<input name="print" type="submit" id="print" value="PRINT" onclick="printpage()" />
</td>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
单击时,将打开一个打印窗口.一旦我关闭打印窗口并再次打开然后单击打印,而不重新加载,则它将无法工作.