Php 用一个值回显背景图像
我回想起这样一幅画面:Php 用一个值回显背景图像,php,css,echo,Php,Css,Echo,我回想起这样一幅画面: $newString = $thumbPre.'profilemain'.$thumbPost; echo "<img src='http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error'>"; $newString=$thumbPre.profilemain.$thumbPost; 回声“; 现在我想把这个图像作为背景图像,我试着这样做,
$newString = $thumbPre.'profilemain'.$thumbPost;
echo "<img src='http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error'>";
$newString=$thumbPre.profilemain.$thumbPost;
回声“;
现在我想把这个图像作为背景图像,我试着这样做,但不起作用:
echo '<div style="background-image:url('http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error');"></div>';
echo';
嵌套撇号需要使用反斜杠
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\' alt=\'error\');></div>';
echo'嵌套撇号需要使用反斜杠
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\' alt=\'error\');></div>';
echo'这看起来非常混乱,但是你需要1,转义引号,2,在其中连接你的路径
让我给你举个例子。我误解了一点问题,但这将有助于你们向前迈进,尤其是为了清洁
以下是一个例子:
$imagePath ='PATH TO IMAGE HERE';
echo '<div style="background-image:url(\'' .$imagePath. '\')" >STUFF HERE </div>';
$imagePath='PATH TO IMAGE HERE';
呼应“这里的东西”;
这看起来非常混乱,但您需要1,转义引号,2,在其中连接您的路径
让我给你举个例子。我误解了一点问题,但这将有助于你们向前迈进,尤其是为了清洁
以下是一个例子:
$imagePath ='PATH TO IMAGE HERE';
echo '<div style="background-image:url(\'' .$imagePath. '\')" >STUFF HERE </div>';
$imagePath='PATH TO IMAGE HERE';
呼应“这里的东西”;
首先,删除alt='error'
,因为背景图像
没有alt
参数,img
有(您可能认为可以从原始代码中使用该参数)。在尝试使用时,您的背景不会显示出来
你的背景不会显示出来,除非你在那个div里面有内容。我已经添加了内容
,作为一个例子
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\');">Content</div>';
echo“内容”;
您要么必须转义封装引号,要么将它们全部删除
echo '<div style="background-image:url(http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.');">Content</div>';
echo“内容”;
错误报告还会引发解析错误,例如:
分析错误:语法错误,意外的“alt=”(T_常量_封装的_字符串),应为“,”或“;”
首先,删除alt='error'
,因为background image
没有alt
参数,img
有(您可能认为可以从原始代码中使用该参数)。在尝试使用时,您的背景不会显示出来
你的背景不会显示出来,除非你在那个div里面有内容。我已经添加了内容
,作为一个例子
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\');">Content</div>';
echo“内容”;
您要么必须转义封装引号,要么将它们全部删除
echo '<div style="background-image:url(http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.');">Content</div>';
echo“内容”;
错误报告还会引发解析错误,例如:
分析错误:语法错误,意外的“alt=”(T_常量_封装的_字符串),应为“,”或“;”