-5

New to PHP. Having a problem with a "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING"

Here is the code:

<?php 
$moreLink = '';
if ($data->node_type == "product_book") :
$path = str_replace(' ', '-', strtolower($data->node_title));
$moreLink = '<a href="/books/'.$path'">Read more > </a>';
else :
$path = drupal_get_path_alias( 'node/' . $data->nid);
$moreLink = '<a href="/'.$path.'">Read more > </a>';
endif;
return $moreLink;
?>

Any help would be greatly appreciated. Thanks. -Matt

  • @JohnConde In fact the reference question does not include this particular error (with `T_CONSTANT_ENCAPSED_STRING`) – h2ooooooo May 01 '14 at 14:45
  • @h2ooooooo Really? I'm surprised. Maybe we need to add this question to it? Or find another one to be the canonical answer for it? – John Conde May 01 '14 at 14:47
  • @JohnConde Technically you can click [Parse error: syntax error, unexpected T_XXX](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12770089/#12770089), then [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/q/18050071/367456) and then [Unexpected T_CONSTANT_AND_ENCAPSED](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them/18092288#18092288). Perhaps we should just add this to the reference question. – h2ooooooo May 01 '14 at 14:49
  • @h2ooooooo Yeah. I'd like to see this specific error message listed in the TOC in the question. It would be a lot easier to find IMHO. – John Conde May 01 '14 at 14:50
  • @JohnConde What's the norm on SO for this sort of reference? All the answers seem to be part of the question. Are "external" (link to an answer on other question) OK, or should there be an answer added with a link to the specific "external" answer? – h2ooooooo May 01 '14 at 14:52
  • @h2ooooooo Not entirely sure. We may need to go into the PHP chat room to get feedback on this. – John Conde May 01 '14 at 14:57

1 Answers1

1

You forget a . on this line:

$moreLink = '<a href="/books/'.$path'">Read more > </a>';

It should be

$moreLink = '<a href="/books/'.$path.'">Read more > </a>';
                                    ^ here
Albzi
  • 15,431
  • 6
  • 46
  • 63