title: Parse error unexpected t_constant_encapsed_string php
body: <p>I have a for loop to go through an array I get from a web service that are paths to images, that I want to insert into  and  tags and print as much as there are in the array. The problem is that I'm getting the encapsed string error and I can't see where should I correct my code. </p>
  
  <p>Here is the php code:</p>
  
  <pre><code>if(count($curl_odgovor_decoded) &gt; 0)
          {
              $format ='';
  
              for ($i=1; $i &lt; count($curl_odgovor_decoded); $i++) { 
                  if($curl_odgovor_decoded[0]['slika'.$i] != null)
                  {
                      $format.='&lt;div class="col-sm-3 col-xs-6"&gt;
                      &lt;a href="'.$curl_odgovor_decoded[0]['slika'.$i].'" title="slika'.$i'" data-gallery="#blueimp-gallery"&gt;
                      &lt;img class="img-responsive img-customer" src=""&gt;
                      &lt;/a&gt;&lt;/div&gt;';
                      echo $format;
                  }
  
              }
          }
          else
          {
              $format = ' &lt;div class="col-sm-3 col-xs-6"&gt;
              &lt;p&gt;Za ovaj oglas jos uvek nisu postavljene fotografije smestaja&lt;/p&gt;
              &lt;/div&gt;';
  
              echo $format;
          }
  </code></pre>
  
  <p>The parse error is  in the for loop, at the end of the format string, the part where a and div tags are closed.</p>
  
  <p>Also, if this is a bad practice to generate html content, please tell me and suggest another solution :)</p>
  
  <p>EDIT:</p>
  
  <p>I have corrected the code, and it works, but the for loop doesn't work as it is supposed to. It always prints out only one div with the correct image, and it is supposed to print out 4 of them. When I echo format 4 times by myself without using a loop, every thing is fine. </p>
  
  <p>If I do this it works fine(but that's just bad practice):</p>
  
  <pre><code>echo '&lt;div class="col-sm-3 col-xs-6"&gt;
          &lt;a href="'.$curl_odgovor_decoded[0]['slika1'].'" title="slika1" &gt;
          &lt;img class="img-responsive img-customer" src="'.$curl_odgovor_decoded[0]['slika1'].'"&gt;
          &lt;/a&gt;&lt;/div&gt;';
          echo '&lt;div class="col-sm-3 col-xs-6"&gt;
          &lt;a href="'.$curl_odgovor_decoded[0]['slika2'].'" title="slika2" &gt;
          &lt;img class="img-responsive img-customer" src="'.$curl_odgovor_decoded[0]['slika2'].'"&gt;
          &lt;/a&gt;&lt;/div&gt;';    
          echo '&lt;div class="col-sm-3 col-xs-6"&gt;
          &lt;a href="'.$curl_odgovor_decoded[0]['slika3'].'" title="slika3" &gt;
          &lt;img class="img-responsive img-customer" src="'.$curl_odgovor_decoded[0]['slika3'].'"&gt;
          &lt;/a&gt;&lt;/div&gt;';
          echo '&lt;div class="col-sm-3 col-xs-6"&gt;
          &lt;a href="'.$curl_odgovor_decoded[0]['slika4'].'" title="slika4" &gt;
          &lt;img class="img-responsive img-customer" src="'.$curl_odgovor_decoded[0]['slika4'].'"&gt;
          &lt;/a&gt;&lt;/div&gt;';
  </code></pre>
  
  <p>I cannot find the problem with the for loop, why would it print out just one div with the image?</p>