If the php syntax error has been corrected, then doing what was suggested did work and the current problem is due to something else. (As a side note, if you put php variables inside a double-quoted string, when php parses the string it produces the same tokenized byte-code as if you had used concatenation, without needing to type the extra quotes and dots yourself.)
It would take seeing all the code needed to reproduce this new problem to help narrow down the dozen different things that could be wrong with it, to just a few or a single thing that can then be investigated further. Except for very overt problems and errors, there’s not a ‘one symptom’ is always caused by a ‘single problem’ relationship in programming.
As to the initial problem in this thread. The book publisher used full-width justification to make the longer lines fill the width of the page. This however introduced spaces in the ‘published’ code where they are not functionally allowed. Duplicating what you see in a book or in a video isn’t actually teaching you the requirements/meaning of what you are doing, so when it comes to finding and fixing a problem or writing your own code, you don’t have any idea what is actually required. This is where the documentation comes in handy. The link that chorn posted to in the php.net documentation specifically states that this syntax requires the $ to immediately follow the { for it to work.