首页 > 解决方案 > powershell用php元素编写html

问题描述

我正在尝试使用 powershell 编写一个 html 页面。我使用的 html 代码也有 javascript 和 php 元素。所有代码都被写入我正在使用 powershell 编写的文件中,但是当我在浏览器中查看它时,它只会显示一个空白页面。我错过了什么?

$htmlexport = @"
<?php include("top.php"); ?>
<!DOCTYPE html>
<html>
<head>

  <script type="text/javascript" src="http://127.0.0.1/weather/js/hanis_min.js"></script>
  <title></title>
</head>
<body onload="HAniS.setup('http://127.0.0.1/weather/models/RAP/RAP-USA-PTYPE-config.txt','handiv')">
  <div id="main-copy-bot" style="text-align:left">
    <br>
    <div id="main-copy">
      <center>
        <table width="50%" cellpadding="5" cellspacing="5">
          <tr>
            <th><?php
            include("ltmenu-rap.php");
            ?></th>
            <th>
              <div id="handiv" style="width:1100px;height:825 background-color:#808080;"></div><br>
            </th>
            <th><?php
            include("rtmenu.php");
            ?></th>
          </tr>
        </table><?php
        include("bottom.php");
        ?>
      </center>
    </div>
  </div>
</body>
</html>
"@

$htmlexport | Out-File C:\xampp\htdocs\weather\testbatch5.php

标签: javascriptphphtmlpowershell

解决方案


如果您能够成功手动保存文件但使用 PowerShellOut-File失败,则问题可能与编码有关。Windows PowerShell(版本 5.1 或更低版本)中的Out-File默认编码UnicodeUTF-16le. 在 Windows 上手动保存文件可能使用不同的编码,例如系统的活动代码页(通常是 ANSI)或UTF-8(在 Windows 中使用 BOM)。您可以简单地使用-Encoding开关来指定编码。

# Encodes in UTF8 with BOM in Windows PowerShell
$htmlexport | Out-File C:\xampp\htdocs\weather\testbatch5.php -Encoding UTF8

请注意,在 PowerShell Core (v6+) 中,Out-File的默认编码是 UTF8,没有 BOM ( utf8NoBOM)。


推荐阅读