开发者

PHP HTML output

开发者 https://www.devze.com 2022-12-14 02:34 出处:网络
What is the correct way to output html inside a switch structure? I\'ve tried both below, none work: <?php

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号