0

I am facing a syntax error problem in PHP. Appreciate if someone can help me understand what is going wrong here.

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in:

The line causing this issue is:

if ($custom_logo){
     echo '#logo a { background: url(''.$custom_logo.'') left center no-repeat; }';
}
chris85
  • 23,846
  • 7
  • 34
  • 51
enigma
  • 63
  • 6

2 Answers2

2

You need to use escape char when you want to use 2 times single quote...

if ($custom_logo){ echo '#logo a { background: url(\''.$custom_logo.'\') left center no-repeat; }'; }
Naga
  • 2,190
  • 3
  • 16
  • 21
1

Using heredoc is another approach, be sure LOGO_CSS is the first text on the line, no leading whitespace.

if (!empty($custom_logo)){
     echo <<< LOGO_CSS
#logo a { background: url('$custom_logo') left center no-repeat; }
LOGO_CSS;
}

http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

user2182349
  • 9,569
  • 3
  • 29
  • 41