Jump to content

help with syntax


ev66

Recommended Posts

Im using this code below to place the value of $a into first cell of a table, what is the correct syntax so that i only have to use one echo statement ? tried all diff combinattions but cant get it.
Thanks

<body>[color=red]<?php[/color] [color=blue]echo '<table width="400" border="1">
  <tr>
    <td>'; echo $a; echo '&nbsp;</td>[/color]
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
'
[color=red]?>[/color]
Link to comment
https://forums.phpfreaks.com/topic/19303-help-with-syntax/
Share on other sites

Use HEREDOC:
[code=php:0]<?php echo <<<HTML
<table width="400" border="1">
  <tr>
    <td>{$a}</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
HTML;
// DO NOT INDENT OR PUT ANYTHING ON THE LINE ABOVE
?>[/code]


Or use this, not the use of the concatenation operator (.)
[code=php:0]<?php echo '<table width="400" border="1">
  <tr>
    <td>' . $a . '</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>'; ?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/19303-help-with-syntax/#findComment-83730
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.