Php 我如何让表格的输出显示在同一行,而不是分开显示?
我需要像下面的例子一样生成我的表单,而不是全部被隔开。嗨,你是怎么做到的? 希望你有一个美好的时光。请帮忙!我是编程新手Php 我如何让表格的输出显示在同一行,而不是分开显示?,php,html,forms,output,Php,Html,Forms,Output,我需要像下面的例子一样生成我的表单,而不是全部被隔开。嗨,你是怎么做到的? 希望你有一个美好的时光。请帮忙!我是编程新手 <html> <head> <title>Test1-1</title> </head> <body> <?php if (filter_has_var(INPUT_POST, "userName")){
<html>
<head>
<title>Test1-1</title>
</head>
<body>
<?php
if (filter_has_var(INPUT_POST, "userName")){
// the form exists, so work with it
$userName = filter_input(INPUT_POST, "userName");
print "<h2>Hi $userName</h2>";
}
if(filter_has_var(INPUT_POST, "morning")){
filter_input(INPUT_POST, "morning");
print"<h2>how are you doing this morning?</h2>";
}
if(filter_has_var(INPUT_POST, "afternoon")){
print"<h2>how are you doing this afternoon?</h2>";
filter_input(INPUT_GET, "afternoon");
}
if(filter_has_var(INPUT_POST, "evening")){
print"<h2>how are you doing this evening?</h2>";
filter_input(INPUT_POST, "evening");
}
if(filter_has_var(INPUT_POST, "plan")){
$plan = filter_input(INPUT_POST, "plan");
print "<h2>Hope you have a wonderful time $plan</h2>";
}
//there's no input. Create the form
print <<< HERE
<form action ="" method = "post">
<fieldset>
<label>Please enter your name</label>
<input type = "text"
name = "userName"/><br>
<label>Time of Day</label>
<input type = "checkbox"
name = "morning"/>
<label>Morning</label>
<input type = "checkbox"
name = "afternoon"/>
<label>Afternoon</label>
<input type = "checkbox"
name = "evening"/>
<label>Evening</label><br>
<label>What are your plans?</label>
<input type = "text"
name = "plan"/><br>
<button type = "submit">
submit
</button>
</fieldset>
</form>
HERE;
// end 'value exists' if
?>
</body>
</html>
测试1-1
解决方案是将
和
标记替换为
和
。这将根据您的需要放置它们。
<html>
<head>
<title>Test1-1</title>
</head>
<body>
<?php
echo '<p>';
if (filter_has_var(INPUT_POST, "userName")){
// the form exists, so work with it
$userName = filter_input(INPUT_POST, "userName");
print "Hi $userName";
}
if(filter_has_var(INPUT_POST, "morning")){
filter_input(INPUT_POST, "morning");
print"how are you doing this morning?";
}
if(filter_has_var(INPUT_POST, "afternoon")){
print"how are you doing this afternoon?";
filter_input(INPUT_GET, "afternoon");
}
if(filter_has_var(INPUT_POST, "evening")){
print"how are you doing this evening?";
filter_input(INPUT_POST, "evening");
}
if(filter_has_var(INPUT_POST, "plan")){
$plan = filter_input(INPUT_POST, "plan");
print "Hope you have a wonderful time $plan";
}
echo '</p>';
//there's no input. Create the form
print <<< HERE
<form action ="" method = "post">
<fieldset>
<label>Please enter your name</label>
<input type = "text"
name = "userName"/><br>
<label>Time of Day</label>
<input type = "checkbox"
name = "morning"/>
<label>Morning</label>
<input type = "checkbox"
name = "afternoon"/>
<label>Afternoon</label>
<input type = "checkbox"
name = "evening"/>
<label>Evening</label><br>
<label>What are your plans?</label>
<input type = "text"
name = "plan"/><br>
<button type = "submit">
submit
</button>
</fieldset>
</form>
HERE;
// end 'value exists' if
?>
</body>
</html>
测试1-1
不同的部分显示在不同的行上的原因是您将它们包含在
标记中
HTML标题元素(如
)是块级元素。请参阅一些文档,以便更好地解释其确切含义,但简而言之(引用链接文档):
浏览器通常在块级元素前后都显示一条换行符
为了避免这种情况,您可以简单地删除
标记,或者用
之类的标记替换它们