您好,我有一封发送给客户的电子邮件,内容如下: ojit_代码 我需要将来自 google api 的脚本添加到 $body 变量中:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "LodgingReservation",
"reservationNumber": "abc456",
"reservationStatus": "http://schema.org/Confirmed",
"underName": {
"@type": "Person",
"name": "John Smith"
},
"reservationFor": {
"@type": "LodgingBusiness",
"name": "Hilton San Francisco Union Square",
"address": {
"@type": "PostalAddress",
"streetAddress": "333 O'Farrell St",
"addressLocality": "San Francisco",
"addressRegion": "CA",
"postalCode": "94102",
"addressCountry": "US"
},
"telephone": "415-771-1400"
},
"checkinDate": "2017-04-11T16:00:00-08:00",
"checkoutDate": "2017-04-13T11:00:00-08:00"
}
</script>
我该怎么做?有任何想法吗? 我无法将“更改为”。
最佳答案
如果我理解这个问题,这应该就是您要找的:
$script = <<<EOF
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "LodgingReservation",
"reservationNumber": "abc456",
"reservationStatus": "http://schema.org/Confirmed",
"underName": {
"@type": "Person",
"name": "John Smith"
},
"reservationFor": {
"@type": "LodgingBusiness",
"name": "Hilton San Francisco Union Square",
"address": {
"@type": "PostalAddress",
"streetAddress": "333 O'Farrell St",
"addressLocality": "San Francisco",
"addressRegion": "CA",
"postalCode": "94102",
"addressCountry": "US"
},
"telephone": "415-771-1400"
},
"checkinDate": "2017-04-11T16:00:00-08:00",
"checkoutDate": "2017-04-13T11:00:00-08:00"
}
</script>
EOF;
$body = '<div>my email content</div>' . $script;
有关 heredoc 的更多信息
可能您需要使用 htmlentities() 方法来编码特殊字符
关于javascript - 如何用javascript初始化php变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30238427/