PHP concatenation with Dompdf

Asked

Viewed 241 times

0

You guys talk beauty ? So I can show all the content in a PDF with html I need to concatenate line by line, so everything Ok. The problem is that when I try to put the $_POST method to show the contents of a dynamic form, I get an error:

  Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\Emp\gerar_pdf.php on line 176

The line that comes from this error is this:

  $html .="<td>$_POST['interrupcao'][$i]</td>";

Here’s a snippet of what I’m trying to show you:

  $html .= "<table>";
  $html .= "<tr>";
  $html .= "<th>INTERRUPÇÕES</th>";
  $html .= "<th>Início</th>";
  $html .= "<th>Término</th>";
  $html .= "</tr>";
  $teste = $_POST['interrupcao'];
   for ($i=0; $i < count($teste); $i++) {
  $html .="<td>$_POST['interrupcao'][$i]</td>";
  $html .="<td>$_POST['inicioint'][$i]</td>";
  $html .="<td>$_POST['terminoint'][$i]</td>";
   }    
  $html .= "<tr>";
  $html .= "</tr>";
  $html .= "</table>";

1 answer

0


You must protect variables with quotes using keys:

 $html .="<td>{$_POST['interrupcao'][$i]}</td>";
 $html .="<td>{$_POST['inicioint'][$i]}</td>";
 $html .="<td>{$_POST['terminoint'][$i]}</td>";

Passing your code through 3v4l: https://3v4l.org/84KM9

  • Thanks =). But now the error has changed kkkk

  • probably $test is an empty variable

  • $test was like $test = $_POST['interruption'];. And I put the $test inside the for. Now I switched to: for ($i=0; $i < sizeof($_POST['interruption']); $i++) {. And it still didn’t work. The error is this: https://jpst.it/17cdH

  • Then the problem has changed. I don’t use dompdf but the step-by-step to solve this is true for all tools that convert html to pdf. Make sure the html generated by php is correct.

  • Okay, thank you =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.