Improved PHP error messages to display the last string matched before a syntax error

- Previously always listed '$end' as the unexpected sequence
Fixed issue with error messages referencing the last valid token rather than the next invalid one
Fixed issue with last valid token's line being referred to in PHP error messages, rather than invalid token's