javascript - 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
解决方案
如果您能够成功手动保存文件但使用 PowerShellOut-File
失败,则问题可能与编码有关。Windows PowerShell(版本 5.1 或更低版本)中的Out-File默认编码Unicode
是UTF-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
)。
推荐阅读
- methods - 从 swiper onSlide 更改访问我的组件的其他方法
- javascript - 如何在 DOM 中对齐 div
- mdx - SQL,MDX,将2个查询的结果合二为一
- java - Java 8 Streams - 为什么我不能对整数流求和?
- php - 使用 xamp 在本地运行 PHP、Mysql 项目
- c++ - Arrayfire 贝塞尔函数
- deep-linking - 是否可以在 Data Studio 中进行深度链接?
- python - 每次运行 RandomForestRegressor 时都会得到不同的结果
- php - PHP 读取服务器根目录内的文件
- jquery - Jquery Datepicker onSelect 不起作用