Html within "echo" php

1

I would like to know how to do this:

<td><a href="edita.php?id=<?php echo $objProg->getid();?>">Alterar</a></td>

Within a echo in php?

    
asked by anonymous 29.03.2016 / 18:54

2 answers

11

You can concatenate (ie join two or more strings) your echo to have this result (as already posted as comment).

<?php
echo '<td><a href="edita.php?id=' . $objProg->getid() . '">Alterar</a></td>';
?>

Another method that "recommend" you to know and test would be the HereDoc that will allow you to add the variables without worrying about the quotation marks and etc., having the same effect.

<?php
echo <<<EOT
<td><a href="edita.php?id=$objProg->getid()">Alterar</a></td>
EOT;
?>
    
29.03.2016 / 19:09
1

You can use the way SK15 spoke, or you can instead use echo to write directly in HTML and just insert info into php for example:

<td>
   <a href="edita.php?id=<?=$objProg->getid();?>">
       Alterar
   </a>
</td>

Use <?= to save code and streamline processing with a clean code! And make it easier ... And if that piece of code is used inside an if, or else, or while, or is ... Close php before it and open again after!

    
01.04.2016 / 07:16