我已经看过多种方式做多行HTML,但我发现这个方法更方便的是这个(除了有一种方法可以将html放在一个单独的页面上,这将是非常棒的)。然而,当我尝试在arduino ide上编译它时,我遇到了错误。这是我得到的错误:
bitluniHomeAutomation:64: error: stray '\342' in program
const char* msj = R”foo(
^
bitluniHomeAutomation:64: error: stray '\200' in program
bitluniHomeAutomation:64: error: stray '\235' in program
bitluniHomeAutomation:70: error: stray '#' in program
background-color: #990033;
^
bitluniHomeAutomation:77: error: stray '\342' in program
</style>”
^
bitluniHomeAutomation:77: error: stray '\200' in program
bitluniHomeAutomation:77: error: stray '\235' in program
bitluniHomeAutomation:78: error: stray '\342' in program
</head>”
^
bitluniHomeAutomation:78: error: stray '\200' in program
bitluniHomeAutomation:78: error: stray '\235' in program
bitluniHomeAutomation:79: error: stray '\342' in program
<body>”
^
bitluniHomeAutomation:79: error: stray '\200' in program
bitluniHomeAutomation:79: error: stray '\235' in program
bitluniHomeAutomation:80: error: stray '\342' in program
<input type=”button” class=”button” value=”Input Button”>
^
bitluniHomeAutomation:80: error: stray '\200' in program
bitluniHomeAutomation:80: error: stray '\235' in program
bitluniHomeAutomation:80: error: stray '\342' in program
bitluniHomeAutomation:80: error: stray '\200' in program
bitluniHomeAutomation:80: error: stray '\235' in program
bitluniHomeAutomation:80: error: stray '\342' in program
bitluniHomeAutomation:80: error: stray '\200' in program
bitluniHomeAutomation:80: error: stray '\235' in program
bitluniHomeAutomation:80: error: stray '\342' in program
bitluniHomeAutomation:80: error: stray '\200' in program
bitluniHomeAutomation:80: error: stray '\235' in program
bitluniHomeAutomation:80: error: stray '\342' in program
bitluniHomeAutomation:80: error: stray '\200' in program
bitluniHomeAutomation:80: error: stray '\235' in program
bitluniHomeAutomation:80: error: stray '\342' in program
bitluniHomeAutomation:80: error: stray '\200' in program
bitluniHomeAutomation:80: error: stray '\235' in program
bitluniHomeAutomation:83: error: missing terminating " character
)foo";
^
/Users/carlospiasentini/Documents/Arduino/bitluniHomeAutomation/bitluniHomeAutomation.ino: In function 'void cssButton()':
bitluniHomeAutomation:64: error: 'R' was not declared in this scope
const char* msj = R”foo(
^
bitluniHomeAutomation:77: error: expected ',' or ';' before '<' token
</style>”
^
bitluniHomeAutomation:85: error: 'message' was not declared in this scope
message.replace("[[MODE]]", String(inputMode));
^
bitluniHomeAutomation:85: error: 'inputMode' was not declared in this scope
message.replace("[[MODE]]", String(inputMode));
^
exit status 1
stray '\342' in program
这是我的HTML代码
void cssButton() {
const char* msj = R”foo(
<!DOCTYPE html>
<html>
<head>
<style>
.button {
background-color: #990033;
border: none;
color: white;
padding: 7px 15px;
text-align: center;
cursor: pointer;
}
</style>”
</head>”
<body>”
<input type=”button” class=”button” value=”Input Button”>
</body>
</html>
)foo";
String message = String(msj);
message.replace("[[MODE]]", String(inputMode));
server.send(200, "text/html", message);
}
我称之为:
server.on("/button", cssButton);
答案 0 :(得分:1)
我相信你正在为Arduino IDE上的ESP8266芯片进行编译。
请注意,在您的代码中,您有:
const char* msj = R”foo(
在这里,您使用卷曲引号 NOT ASCII字符。
为了达到同样的效果,您可以使用ASCII字符 - &gt; &#34; &lt; -
这是{34},如ASCII table所示。
答案 1 :(得分:0)
除上述内容外,您还需要确保字符串中出现的任何引号(例如<input type=”button” class=”button” value=”Input Button”>
中的引号)都已转义。否则,编译器会将它们视为带引号的字符串的结尾,并尝试解析作为语句后的内容。
要逃避它们,请添加一个反斜杠,如下所示:<input type=\"button\" class=\"button\" value=\"Input Button\">
。
或者,您可以在HTML中的任何位置使用单引号。这些不会与包含整个HTML的双引号冲突。