0

I am writing a code to filter a bunch of gallery images using the tags assigned to the images. However I am running into this parse error

Parse error: syntax error, unexpected '}', expecting ',' or ';'

I am baffled coz I see that the "}" it is referring to has been opened and closed correctly. Any help would be greatly appreciated. This is the line thats throwing the error

<button class="cbp-filter-item"><?php if($key == 0){echo 'cbp-filter-item-active'};?> data-filter=".<?php echo strtolower(str_replace(" ","-",$tag)); ?>"><?php echo ucfirst($tag); ?></button> ","-",$tag)); ?>"><?php echo ucfirst($tag); ?></button>

Here's the code snippet >

        <?php if(isset($tagsFilter) && count($tagsFilter)): 
            foreach($tagsFilter as $key=>$tag): 
        ?>
        <button class="cbp-filter-item"><?php if($key == 0){echo 'cbp-filter-item-active'};?> data-filter=".<?php echo strtolower(str_replace(" ","-",$tag)); ?>"><?php echo ucfirst($tag); ?></button>
        <?php endforeach; endif;?>
    </div>

<?php endif;?>

Any help would be greatly appreciated.

Thanks, Sai.

  • `};` <-- Look at this again also what should that be: `","-",$tag)); ?>` A half eaten php line? – Rizier123 Feb 21 '15 at 17:00
  • `{echo 'cbp-filter-item-active'}` → `{echo 'cbp-filter-item-active';}`, perhaps. But what have you got against line breaks? – Biffen Feb 21 '15 at 17:01

1 Answers1

0

Change this line:

<?php if($key == 0){echo 'cbp-filter-item-active'};?> 

With this one:

<?php if($key == 0){echo 'cbp-filter-item-active';} ?>
Babak
  • 419
  • 2
  • 16
  • Ok I have changed it to ` ` Now it says unexpected Endif in the line `?php endforeach; endif;?>1 – user3418385 Feb 21 '15 at 18:49
  • since you didn't put all your script here I can only guess this is what you want: `$tag): ?> ` – Babak Feb 23 '15 at 16:41
  • Sorry for being vague. What I have been trying to do is to filter a set of items based on the k2 tags on my joomla site. Make the first tag active and show the items under it. The parsing error is resolved now but I cannot get the desired result. [Here is the complete script](http://pastebin.com/vJaxHgH9) – user3418385 Feb 24 '15 at 07:12