我的建議是做這樣的事情:
<?php
function ShowHtml()
{
?>
<form action='log.php' method='post'>
<table>
<tr>
<td>username</td>
<td>
<input type='text' name='user' />
</td>
</tr>
<tr>
<td>password</td>
<td>
<input type='password' name='password' />
</td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' name='login' value='submit' />
</td>
</tr>
</table>
</form>
<?php
}
?>
這樣就省去了做一個echo
或print
並且還修復你的語法錯誤(即缺少<
標籤和vaue
應該是value
) 。
此外,在此你可以有一個功能,如:
<?php
function ShowHtml($html)
{
if ($html != null || $html != '' || !empty($html)) # Just a check to make sure then html is set ;P
{
print $html; # could use echo instead, personal preference :)
# Could also add more validation to make sure the html tags themselves are valid and correct
return true;
}
return false;
}
?>
或者你可以做(保持PHP環繞聲):
<?php
$form = "<form action='log.php' method='post'>
<table>
<tr>
<td>username</td>
<td>
<input type='text' name='user' />
</td>
</tr>
<tr>
<td>password</td>
<td>
<input type='password' name='password' />
</td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' name='login' value='submit' />
</td>
</tr>
</table>
</form>";
echo $form; # Or print, your choice :)
# Can also use the bracketed way of echo(...)
# or print(...) for an added layer of
# 'make sure I only print what I want to'
?>
因爲剛剛分配字符串'$ form' 。你沒有迴應內容。 –
打印變量'echo $ form;' – Apb
或'print $ form;' –