将PHP变量字符串插入内联字符串不起作用

Tut*_*sis 4 php tcpdf

我在PHP中有点生锈,目前正在努力做一些非常简单的事情.

$value = "PUPPY";
$html .= '<td>{$value}</td>';
echo $html; // Doesn't work, prints {$value}.... Should be... PUPPY
Run Code Online (Sandbox Code Playgroud)

我知道有一种简单的方法可以做到这一点,但我忘记了,无法在Google或StackOverflow上找到明确的方法.

一旦完成,我需要将html放在一个变量中,它被tcpdf :: writeHtml()使用

我已经尝试过:

$html .= "<td align='right' nowrap>".$value."</td>";
echo $html; // But this outputs a TD tag with attribute nowrap=""  and this is not valid HTML... tcpdf:writeHtml rejects this.
Run Code Online (Sandbox Code Playgroud)

更新:该错误实际上是由于前一段时间弃用的"nowrap"属性的错误使用造成的.

Ora*_*ill 13

单引号字符串不在php中插入.请改用双引号.

$value = "PUPPY";
$html .= "<td>{$value}</td>";
echo $html;
Run Code Online (Sandbox Code Playgroud)


sil*_*ntw 5

$value = "PUPPY";
$html .= "<td>{$value}</td>";
echo $html;
Run Code Online (Sandbox Code Playgroud)

"而不是'

看看吧 documentation about Strings on PHP