在我的代码中,我想定义一个函数/变量/。
它应该看起来像这样:
<?php
//define something here
{
"html code inside here"
}
// some php code
if(...)
{
"output the html
}
我该怎么做?
您需要先将其放入变量/函数中,或者回显下面的html。
选项#1:
$html = "This is test html <a href='http://google.com'>google</a>";
if ( !empty($_POST) )
{
echo $html;
}
选项2:
if ( !empty($_POST) )
{
echo "This is test html <a href='http://google.com'>google</a>";
//Or simply:
?>
This is test html <a href="http://google.com">google</a>
<?php
}
选项#3:
function outputHtml() {
?>
This is test html <a href="http://google.com">google</a>
<?php
}
if ( !empty($_POST) )
{
outputHtml();
}