mvasco mvasco - 4 months ago 18
PHP Question

Inserting HTML and PHP into PHP variable

I am trying to insert HTML and PHP into a PHP variable, but a syntax error is thrown:

$nestedData[] = $row["titulo_anuncio"];
$nestedData[] = $row["texto_anuncio"];
$nestedData[] = $row["fecha_anuncio"];
$nestedData[] = <<<EOD
<div>
<a id="<?php echo $row['emp_id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a>
</div>
EOD;


The error is thrown at the last $nestedData[] variable.

Answer

Try this:

$nestedData[] = $row["titulo_anuncio"];
$nestedData[] = $row["texto_anuncio"];
$nestedData[] = $row["fecha_anuncio"];
$nestedData[] = <<<EOD
<div>
<a id="{$row['emp_id']}" class="edit-link" href="#" title="Edit">
        <img src="edit.png" width="20px" />
        </a>

EOD;

You can't echo $row['emp_id'] within a line defining a string.