回声背景图像的值

I echo out an image like that:

$newString = $thumbPre.'profilemain'.$thumbPost;
echo "<img src='http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error'>";

Now i want the image as a background-image, i tried it like that, but it doesn´t work:

echo '<div style="background-image:url('http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error');"></div>';

Firstly, remove alt='error' because background-image does not have an alt parameter, img does (you probably thought you could use that from your original code). In trying to use that, your background will not show up.

And your background won't show unless you have content inside that div. I've added Content as an example.

echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\');">Content</div>';

You either have to escape the encapsulating quotes, or remove them altogether.

echo '<div style="background-image:url(http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.');">Content</div>';

Error reporting would have also thrown you a parse error such as:

Parse error: syntax error, unexpected '' alt='' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'

you need to use backslashes for nested apostrophes

echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\' alt=\'error\');></div>';

This is going to look super confusing but you need to 1, escape the quotes and 2, concatenate your path within that,

let me give you an example. I misread a bit of the question but this will serve you well moving forward especially for cleanliness sake

here is an example:

$imagePath ='PATH TO IMAGE HERE';
echo '<div style="background-image:url(\'' .$imagePath. '\')" >STUFF HERE </div>';