首页 > 解决方案 > 如何在 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"/>"


我无法弄清楚如何使用正确的引号,以便此代码能够正常工作,因为它在彼此内部使用双引号和单引号

标签: phpsendgrid

解决方案


您必须匹配字符串的开始和结束引号。您以 开始第一个字符串",但'在连接之前以结束它.

如果您想在字符串中加上双引号,请在其周围使用单引号,反之亦然。如果您需要在字符串中包含与使用两个创建它的相同类型的引号,则必须转义内部的引号。

$email->addContent(
    "text/html", '<img src="data:image/png;base64,'.base64_encode($portal['image']).'" width="1024px" height="768px"/>'

推荐阅读