$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How do I fix this: syntax error, unexpected ':', expecting ')'|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin9PV0评论

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'] . '\')";
}
Post a comment

comment list (0)

  1. No comments so far