尽管如此,是否有可能回显整个html和css? 我正在使用if和每个匹配需要生成不同的页面。
另外,在html代码的html代码中,我需要回显一个包含在div中并设置样式的变量。
有什么想法我能做到这一点吗?
我收到以下错误语法错误,意外的T_STRING,期待
由于
echo '<!DOCTYPE html><html lang="mk">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Roboto&subset=cyrillic);
@import url(http://fonts.googleapis.com/css?family=Open+Sans&subset=cyrillic);
@import url(http://fonts.googleapis.com/css?family=Fjalla+One);
*:focus { outline: none; }
::-webkit-scrollbar { width: 0; }
.animate { -webkit-transition: all 0.2s ease-in-out; -moz-transition: all 0.2s ease-in-out; -o-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out; }
body { min-width: 300px; width: auto; max-width: 1100px; height: auto; margin: 0 auto; padding: 0; background-color: white; }
div#container {
position: relative; float: left; clear: none;
width: 100%; height: auto; margin: -3px 0 30px 0; padding: 0 0 50px 0;
background-image: url(guide.jpg); background-position: center bottom; background-repeat: no-repeat; background-size: cover;
background-color: pink;
-webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;
}
html body div#container form {
position: relative; float: left; clear: none;
width: 100%; height: auto; margin: 40px 0 0 0; padding: 0;
}
html body div#container form div#email-container {
position: relative; float: left; clear: none; display: block;
width: 100%; height: auto; margin: 0 auto; padding: 0; overflow: hidden;
text-align: center;
}
html body div#container form div#email-container div#email-input {
position: relative; float: none; clear: none; display: inline-block;
width: auto; height: auto; margin: 0 auto; padding: 25px 40px;
font-family: 'Fjalla One', sans-serif; font-weight: 400; font-size: 40px; letter-spacing: normal;
-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;
background-color: rgba(26, 60, 88, 0.9); color: #ffffff;
cursor: default;
}
label.styled {
position: relative; float: left; clear: none; display: block;
width: auto; height: auto; margin: 0; padding: 10px 20px; overflow: hidden;
font-family: 'Roboto', sans-serif; font-weight: 400; font-size: 15px; letter-spacing: normal;
-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;
background-color: #ffffff; color: rgba(128, 130, 132, 1); box-shadow: inset 0 0 0 2px #b6b6b8;
cursor: pointer;
}
label.styled:before {
position: absolute; float: none; clear: both; top: 0; left: 0; display: block;
width: 40px; height: 40px; margin: 0 0 0 10px; padding: 0;
content: '✔';
font-size: 60px;
opacity: 0;
}
input.styled {
display: none;
}
input.styled:checked ~ label.styled {
padding-left: 50px;
opacity: 1;
background-color: rgba(128, 130, 132, 0.9); color: #ffffff; box-shadow: inset 0 0 0 2px rgba(128, 130, 132, 0.9);;
}
input.styled:checked ~ label.styled:before {
top: -10px; left: -2px;
opacity: 1; color: rgba(255, 255, 255, 0.4);
}
</style>
</head>
<body>
<div id="container" class="animate">
<form method="post" action="$action" class="animate">
<input type="hidden" name="mode_login">
<input type="hidden" name="redirect" value="$redirect">
<input type="hidden" name="accept_terms" value="yes">
<div id="email-container">
<div id="email-input">' . $_POST['fes-email'] . '</div>
</div>
</div>
<input type="checkbox" class="styled animate" id="checkbox-tnc-accept">
<label class="styled animate" for="checkbox-tnc-accept">Ги прифаќам Условите и правилата <br> за користење на овој сервис</label>
<button type="submit" value="Enter">Продолжи</button>
</form>
</body>
</html>';
答案 0 :(得分:1)
echo '...assuming the previous part of the entire code are also present...
<form>
<div id="email-input">' . $_POST['fes-email']; . '</div>
</form>
...';
注意在$ _POST之前我已经删除了回声;如果你已经回响,没有理由开始回声。当你发布'。 $ _POST ['fes-email']。 '你只是允许变量;它一直在运行回声,所以所有新的回声都会让它感到困惑。如果你必须以这种方式拥有它,那么有可能更好地拥有
的内容包括/ YourForm.php 然后在YourForm.php中添加您想要的HTML,然后在index.php add
中require_once( “包括/ YourForm.php”);
虽然我不同意你现在的做法,但我发布的内容应该有效。 不确定为什么要求不作为代码格式化..抱歉。
答案 1 :(得分:1)
我建议你不要用php打印html东西,只需关闭php标签并编写正常的html,所以在这里我删除了大的echo语句并编写了正常的html。这使得代码更加干净,你可以更好地了解什么是HTML以及PHP在哪里。
所以你的PHP代码:
<div id="email-input">' . $_POST['fes-email'] . '</div>
如果你没有在echo语句中使用它,请使用:
<div id="email-input"><?= $_POST['fes-email'] ?></div>
这几乎与:
相同<div id="email-input"><?php echo $_POST['fes-email']; ?></div>
另外,对于有用的错误消息,您可以使用以下行打开错误报告:
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
?>
您可以将它们放在您的php文件之上,并确保它们仅在分段时打开!
整个代码看起来像这样:
<!DOCTYPE html>
<html lang="mk">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Roboto&subset=cyrillic);
@import url(http://fonts.googleapis.com/css?family=Open+Sans&subset=cyrillic);
@import url(http://fonts.googleapis.com/css?family=Fjalla+One);
*:focus { outline: none; }
::-webkit-scrollbar { width: 0; }
.animate { -webkit-transition: all 0.2s ease-in-out; -moz-transition: all 0.2s ease-in-out; -o-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out; }
body { min-width: 300px; width: auto; max-width: 1100px; height: auto; margin: 0 auto; padding: 0; background-color: white; }
div#container {
position: relative; float: left; clear: none;
width: 100%; height: auto; margin: -3px 0 30px 0; padding: 0 0 50px 0;
background-image: url(guide.jpg); background-position: center bottom; background-repeat: no-repeat; background-size: cover;
background-color: pink;
-webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;
}
html body div#container form {
position: relative; float: left; clear: none;
width: 100%; height: auto; margin: 40px 0 0 0; padding: 0;
}
html body div#container form div#email-container {
position: relative; float: left; clear: none; display: block;
width: 100%; height: auto; margin: 0 auto; padding: 0; overflow: hidden;
text-align: center;
}
html body div#container form div#email-container div#email-input {
position: relative; float: none; clear: none; display: inline-block;
width: auto; height: auto; margin: 0 auto; padding: 25px 40px;
font-family: 'Fjalla One', sans-serif; font-weight: 400; font-size: 40px; letter-spacing: normal;
-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;
background-color: rgba(26, 60, 88, 0.9); color: #ffffff;
cursor: default;
}
label.styled {
position: relative; float: left; clear: none; display: block;
width: auto; height: auto; margin: 0; padding: 10px 20px; overflow: hidden;
font-family: 'Roboto', sans-serif; font-weight: 400; font-size: 15px; letter-spacing: normal;
-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;
background-color: #ffffff; color: rgba(128, 130, 132, 1); box-shadow: inset 0 0 0 2px #b6b6b8;
cursor: pointer;
}
label.styled:before {
position: absolute; float: none; clear: both; top: 0; left: 0; display: block;
width: 40px; height: 40px; margin: 0 0 0 10px; padding: 0;
content: '✔';
font-size: 60px;
opacity: 0;
}
input.styled {
display: none;
}
input.styled:checked ~ label.styled {
padding-left: 50px;
opacity: 1;
background-color: rgba(128, 130, 132, 0.9); color: #ffffff; box-shadow: inset 0 0 0 2px rgba(128, 130, 132, 0.9);;
}
input.styled:checked ~ label.styled:before {
top: -10px; left: -2px;
opacity: 1; color: rgba(255, 255, 255, 0.4);
}
</style>
</head>
<body>
<div id="container" class="animate">
<form method="post" action="$action" class="animate">
<input type="hidden" name="mode_login">
<input type="hidden" name="redirect" value="$redirect">
<input type="hidden" name="accept_terms" value="yes">
<div id="email-container">
<div id="email-input"><?= $_POST['fes-email'] ?></div>
</div>
</div>
<input type="checkbox" class="styled animate" id="checkbox-tnc-accept">
<label class="styled animate" for="checkbox-tnc-accept">Ги прифаќам Условите и правилата <br> за користење на овој сервис</label>
<button type="submit" value="Enter">Продолжи</button>
</form>
</body>
</html>
修改强>
如果你在if语句中有这个echo语句,你仍然不需要那样打印:D
作为一个例子(伪代码):
<?php
if(condition) {
echo "<div>HTML STUFF</div>"; //Don't do it that way
} else {
?>
<div>Put your HTML stuff here</div>
<?php
}
?>
此外,如果你必须连接东西:
//v Your variable here
"String is here" . $myVariable . " string goes further"
//^String start ^ ^Concatenate ^ ^ ^String ends
// |Break the string |
有关连接的详细信息,请参阅手册:http://php.net/manual/en/language.operators.string.php
我还建议你不要编写CSS内联或样式标签。您可以使用*.css
编写自己的CSS文件,然后将其包含在html head标记中:
<link rel="stylesheet" type="text/css" href="yourCssFile.css">
答案 2 :(得分:0)
为什么要在PHP
文件中回显HTML。您可以做的是,您可以在您的条件中包含HTML文件。例如: -
if(condition 1)
{
include "one.php";
}
else if(condition 2)
{
include "two.php";
}
在你的one.php和two.php中你有你的HTML,在你的情况下你的所有HTML都将转到其中一个文件。在该文件中,您可以回显您的变量
<div id="email-input"><?php echo $_POST['fes-email']; ?></div>