HTML字符串中的PHP变量

时间:2015-12-03 18:30:53

标签: php html

我从AJAX表单中收到一些信息,我需要生成一封HTML电子邮件,其中将使用此表单中的一些信息。

例如,我想发送像

这样的基本内容
>>> def test():
...     yield 1
...     return 2
...
>>> gen = Generator(test())
>>> for i in gen:
...    print(i)
...
1
>>> print(gen.value)
2

如何在没有连接的情况下将$ information变量插入段落中(使用它非常痛苦,因为电子邮件HTML的结构非常复杂)?

2 个答案:

答案 0 :(得分:2)

如果你想在没有concat的情况下将vars添加到变量中,那么也许你正在寻找类似这样的东西

$information = "Info";
$msg = "<html><body>
 <p>Bla-bla-bla $information</p></body></html>";

使用双引号 请注意var $ information是否为以下数组:

$information['info'] = "Info";
$information['id_info'] = 1;
$msg = "<html><body>
 <p>Bla-bla-bla $information[info]</p>
 <a href\"somepage.php?id=$information[id_info]\">Link</a></body></html>";

双引号和单引号

$email = 'someone@example.com';
$var = 'My email is $email'; // My email is $email
$var = "My email is $email"; // My email is someone@example.com

答案 1 :(得分:1)

有不同的方法:

1)你可以使用&#34;。&#34;

例如:

$msg = '<html><body>
 <p>Bla-bla-bla'. $information.'</p></body></html>';

2)您可以使用双引号:

 $msg = "<html><body>
 <p>Bla-bla-bla $information</p></body></html>";