0

I need the following setup:

<ul>
  <li>8</li>
  <li class="active">9</li>
  <li>10</li>
</ul> 

I am trying to do this with php heredoc:

$pos = $_GET["pagination"];
$pagination = <<EOD
<ul>
  <li>{$pos-1}</li>
  <li class="active">$pos</li>
  <li>{$pos+1}</li>
</ul>
EOD;

But I get error:

Parse error: syntax error, unexpected token "-", expecting "->" or "?->" or "{" or "[" in ...

The only other solutions I can think of is using multiple variables or a function in heredoc. I think there must be a straight forward way to achieve this.

user31782
  • 7,087
  • 14
  • 68
  • 143
  • That post doesn't tell how to directly execute _expressions_ in heredoc, like `eval` function. I already know that method. – user31782 Jan 11 '22 at 09:20
  • 1
    Well that _is_ the method. Just wrap your expression in a little function. – ADyson Jan 11 '22 at 09:30

0 Answers0