Como escrever o código html dentro de [fechado]

quero criar uma tabela dentro do programa php .. Há alguma maneira que eu poderia criar tabela dentro do script php.?

<?php html code to create table ?>
 29
Author: Karan Bhatia, 2013-08-09

4 answers

Podes fazer como

HTML no PHP :

<?php
     echo "<table>";
     echo "<tr>";
     echo "<td>Name</td>";
     echo "<td>".$name."</td>";
     echo "</tr>";
     echo "</table>";
?>
Ou podes escrever assim.

PHP em HTML :

<?php /*Do some PHP calculation or something*/ ?>
     <table>
         <tr>
             <td>Name</td>
             <td><?php echo $name;?></td>
         </tr>
     </table>


<?php /*Do some PHP calculation or something*/ ?> Significa:
Você pode abrir uma tag PHP com <?php, Agora adicione o seu código PHP, depois feche a tag com ?> e depois escreva o seu código html. Quando necessário adicionar mais PHP, basta abrir outra tag PHP com <?php.

 82
Author: Gautam3164, 2016-07-05 02:08:40

Pode entrar e sair do contexto do PHP Usando as marcas<?php e ?>. Por exemplo...

<?php
$array = array(1, 2, 3, 4);
?>

<table>
<thead><tr><th>Number</th></tr></thead>
<tbody>
<?php foreach ($array as $num) : ?>
<tr><td><?= htmlspecialchars($num) ?></td></tr>
<?php endforeach ?>
</tbody>
</table>

Também ver sintaxe alternativa para estruturas de controlo

 11
Author: Phil, 2013-08-09 05:13:22
Tenta assim:
<?php 
    $name='your name';
    echo '<table>
       <tr><th>Name</th></tr>
       <tr><td>'.$name.'</td></tr>
    </table>';
?>

Actualizado

<?php 
    echo '<table>
       <tr><th>Rst</th><th>Marks</th></tr>
       <tr><td>'.$rst4.'</td><td>'.$marks4.'</td></tr>
    </table>';
?>
 2
Author: Rohan Kumar, 2013-08-09 05:14:58

Pode colocar o código em qualquer lugar

<input class="my_<? print 'test' ?>"  />
 1
Author: Notepad, 2013-08-09 06:45:29