PHP HTML output
What is the correct way to output html inside a switch structure?
I've tried both below, none work:
<?php
switch($x){
case "a":
$var = <<< EOM;
...the html...
EOM;
break;
case "b":
...some code...
break;
}
?>
OR <?php switch($x){
case "a":
?>
...the html...
<?php
break;
case "b":
...some code...
break;
}
?>
More info开发者_高级运维:
switch ($_REQUEST['act']){
case 'editdiretorio':
$sql="select * from diretorio where did=$_GET[edit]";
$row=mysql_fetch_assoc(mysql_query($sql));
?>
<h1>Cadastro de Serviço</h1>
<form id="fdiretorio" method="post" action="diretorioconfirm.php">
<?php if($edit){echo "<input name='act' type='hidden' value='update'>";?>
Nome completo de quem preenche o questionário:<br />
<input type="text" name="dnome" class="form-default" style="width:200px;" value="<?php echo "$row[dnome]";?>"/>
<br />
... more 400 lines of code ...
<?php
break;
case "b":
... other code ...
There is no correct way. Outputting HTML within a switch is the same as outputting it anywhere else.
There's no correct way perse, both should work.
In your first example you need to make sure there is no space between <<< and EOM and no semicolon afterwards.
Example:
$myvar = <<<END
<div>My html here</div>
END;
echo $myvar;
another option would be to use:
echo "<div>My html here</div>";
The second example should work, except you said <php
instead of <?php
精彩评论