2016-07-29 68 views
-5

我试图插入HTML和PHP为PHP变量,而是一个语法错误被抛出:插入HTML和PHP到PHP变量

$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; 

该错误是在最后$ nestedData []变量抛出。

+1

你已经在PHP。阅读PHP手册中的heredoc页面,了解如何输出变量。 http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc(特别是标题为“Example#2 Heredoc string quoting example”的位) – ceejayoz

+0

应该有抛出你一个解析错误 –

+0

谢谢你@ceejayoz – mvasco

回答

1

试试这个:

$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;

您无法在定义字符串的行内回显$row['emp_id']

+0

谢谢你,那作品 – mvasco