-2

I'm trying to loop through an array and pass the values into HTML. My loop echos a large block of code. This is a small portion of the code I'm struggling with.

<p class='gl-item-title'>'.$array['title']'</p>
<p class='gl-item-category'>'.$array['type']'</p>

I get this error message

Parse error:

syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\MAMP\htdocs\simsestate\Sims-esate\index.php on line 223

I don't understand this error. Would somebody give tips on how to echo big chunks of HTML in PHP?

halfer
  • 19,824
  • 17
  • 99
  • 186
Flo SEBT
  • 11
  • 1

3 Answers3

0
<p class='gl-item-title'>'.$array['title'].'</p>
<p class='gl-item-category'>'.$array['type'].'</p>

When you join strings you have to use dot, I don't know how rest of your code looks like but in this part you forgot dot after array index variable

semafor
  • 81
  • 8
0

Use double quotes " or escaped single quotes \' for your HTML, additionally you miss a . after $array[''] variables

echo '<p class="gl-item-title">'.$array['title'].'</p>';
echo '<p class="gl-item-category">'.$array['type'].'</p>';

The above can be written also like this:

<p class="gl-item-title"><?php echo $array['title']; ?></p>
<p class="gl-item-category"><?php echo $array['type']; ?></p>
0

You're going to need another dot after the variable. Try this:

echo '<p class=\'gl-item-title\'>'.$array['title'].'</p>';
thatrandomguy
  • 56
  • 1
  • 6