Developer Snippet Diary

Fontawesome rating render module in php

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<?php 
  $rating = 3.4;
  $full_stars = floor($rating);
  $empty_stars = 5 - ceil($rating);
  $half_star = ($rating - $full_stars > 0) ? true : false;
  $rating_render = str_repeat('<i class="fa fa-star"></i>',$full_stars);
  $rating_render.=str_repeat('<i class="fa fa-star-half-o"></i>',$half_star);
  $rating_render.=str_repeat('<i class="fa fa-star-o"</i>',$empty_stars);
  echo $rating_render;
  ?>
</body>
</html>

Posted by: R GONDAL
Email: rizikmw@gmail.com