I'm trying to change the code for displaying images for reviews. The previous code has 5 images of stars. The first image has one star, the next two and so on. The width of each image is the same so the alignment is always correct. The code that was used is
$p_stars = '<img src="images/stars_' . $rating . '.png">';
The above results in a string of stars depending on the rating, like
****
*****
*
***
My thought was to replace the images with font-awesome icons to make it easier to control the color, which requires less maintenance should the color or number of stars need changing. I did this and it works fine but the amount of code it takes is far more than with the images. So my questions are:
- Should I stick with the images?
- Is there a better way to code for the icon method?
Here's the code for the icon method:
<style>
.stars {color:#FB9802;}
.stars-hide {color:#fff;}
</style>
$p_stars = '';
$p = 0;
while ($p < 5) {
for ($x = 0; $x < $rating; ++$x) {
$p_stars .= '<i class="fas fa-star stars"></i>';
$p++;
}
if ($p == 5) break;
for ($x = $p; $x < 5; ++$x) {
$p_stars .= '<i class="fas fa-star stars-hide"></i>';
$p++;
}
}