Can somebody explain me why the small piece of code doesn’t work?
This is the error what is given:
Parse error: syntax error, unexpected ‘=’ in /var/www/g35003/
$img_attributes= style='max-height: 100px; max-width: 100px' . 'alt="'.$product['product_name'].'"';
If this is PHP and you are trying to assign a string to a variable, there should be quotes arround the string.
Here, this specific portion of code is causing an error :
There should be some kind of quote after the first = sign.
Something like this should work much better, for instance :
As a sidenote : maybe some kind of escaping could be helpful, for the
$product['product_name']part ? to make sure it doesn’t contain any HTML that would break your markup.See
htmlspecialchars, for instance.For instance, if your product name is initialized this way :
Then, using the portion of code I posted earlier will get you this output :
Which is not that nice…
Using
htmlspecialchars, like this :The output would become :
Which, at least, is a portion of valid-HTML 🙂