php - 如何在 PHP 中修复双引号/单引号
问题描述
这应该是一个简单的问题,但我发现很难得到一个有效的答案,我使用的是 Sendgrid php api,它要求我在这个布局中执行以下代码。
在我的代码中,我有:
//this part is the sendgrid part:
$email->addContent(
"text/html", "//i need to put the bottom image code into here"
<?php echo '<img src="data:image/png;base64,'.base64_encode($portal['image']).'"width="1024px" height="768px"/>'; ?>
最终结果应类似于:
$email->addContent(
"text/html", "<img src="data:image/png;base64,'.base64_encode($portal['image']).'"width="1024px" height="768px"/>"
我无法弄清楚如何使用正确的引号,以便此代码能够正常工作,因为它在彼此内部使用双引号和单引号
解决方案
您必须匹配字符串的开始和结束引号。您以 开始第一个字符串"
,但'
在连接之前以结束它.
。
如果您想在字符串中加上双引号,请在其周围使用单引号,反之亦然。如果您需要在字符串中包含与使用两个创建它的相同类型的引号,则必须转义内部的引号。
$email->addContent(
"text/html", '<img src="data:image/png;base64,'.base64_encode($portal['image']).'" width="1024px" height="768px"/>'
推荐阅读
- java - 在java中将.properties文件字符串转换为整数
- javascript - 如何使用特定字母对字符串数组进行排序?
- shell - 当 Maven 在 shell 脚本中构建失败时,在 Groovy 函数中返回布尔值
- web - 是否可能的产品被选中“订阅产品”字段自动创建订阅?
- c# - 如何在 C# 中传递变量的名称?
- php - 字符串到嵌套数组
- php - 允许访问 www/html 文件夹之外的文件
- python - max 和 np.max 的区别
- javascript - 遍历 json 对象,同时将其键值与 javascript 中的模式匹配
- c# - Dotvvm 运行时绑定到“对象”类型