From the course: PHP for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

What on earth is T_ENCAPSED_AND_WHITESPACE?

What on earth is T_ENCAPSED_AND_WHITESPACE? - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

What on earth is T_ENCAPSED_AND_WHITESPACE?

This is one of the most enigmatic error messages you're likely to encounter in PHP. Fortunately, it's easy to deal with. Don't worry about this expecting identifier T_string or variable and all that. All you need to take notice of is this T in caps and white space and the line where it occurs. It's on line 19 so let's go to the editing program and look at it. And the problem is that this is a double quoted string and inside it is an associative array element. You can't do it just like that. You need to wrap the associative array element in a pair of curly braces, so curly brace before the dollar sign. Add a curly brace after the closing square bracket. Save the page. Go back to the browser. And the problem is sorted. The associative element is now displayed correctly. Just one little thing about that. Don't try to make your code look a little bit tidier by putting a space after that curly brace and a space at the end here. Let's just see what happens. Save the page. Reload the…

Contents