I’m trying to create a PHP script that shows a Twitch stream embed only when the channel is currently broadcasting. However, I keep running into this error message:
FATAL ERROR syntax error, unexpected ‘http’ (T_STRING), expecting ‘,’ or ‘;’ on line number 8
The basic idea is to check if the stream is active using Twitch’s API and then conditionally display the embedded player. What am I doing wrong with the syntax here?
Your echo statement breaks across multiple lines without proper concatenation. PHP sees the line break and thinks the string ended, then hits the URL on the next line and throws a syntax error. You need to escape the newlines or concatenate properly. Try this:
You could also use heredoc syntax - it handles multiline strings much better. BTW, that Kraken API you’re using is deprecated. Switch to the newer Helix API with proper auth headers for better reliability.
Your multiline echo is breaking because PHP sees each new line as a separate statement. That’s why you’re getting the ‘http’ error - PHP thinks the URL is a new command.
I’d use double quotes and escape when needed - cleaner to read. Also, file_get_contents can fail silently, so add error handling for when the API request fails.