最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I fix this: syntax error, unexpected ':', expecting ')'

programmeradmin6浏览0评论

Here is the line that is effecting my site from loading...I am just getting a blank page for my site. Please help as my business site is obviously down. Thank you in advance to whomever can help me.

$bg = (!$bgimage == '') ? 'style="background-image:url'("".$bgimage[url].'")' : '';

Here is the line that is effecting my site from loading...I am just getting a blank page for my site. Please help as my business site is obviously down. Thank you in advance to whomever can help me.

$bg = (!$bgimage == '') ? 'style="background-image:url'("".$bgimage[url].'")' : '';

Share Improve this question asked Feb 13, 2022 at 21:20 Steve BonillaSteve Bonilla 1
Add a comment  | 

1 Answer 1

Reset to default 0

Your code:

$bg = (!$bgimage == '') ? 'style="background-image:url'("".$bgimage[url].'")' : '';

There's a confusion with the quote marks. You're closing your ' too early, but it's really hard to see in a construction like this. (Also, the array index needs to be wrapped in quotes, either single or double.)

$bg = (!$bgimage == '') ? 'style="background-image:url("'.$bgimage['url'].'")' : '';

might clear up the PHP error, but I'm not sure it'll still do what you want it to. There's still some confusion with quote marks in the CSS; also, is $bgimage a string or an array?

I'd recommend not using the ternary operator, in this case, to make the code more readable.

$bg = '';
if ( ! empty( $bgimage ) ) {
    $bg = 'style="background-image:url(\'' . $bgimage['url'] . '\')";
}
发布评论

评论列表(0)

  1. 暂无评论