5 start rating with html in php

Function return the html structured star with both rated and not-rated.

Call function to get star ratings
echo rating_html(4);

//Function for html star rating
function rating_html($product_rating=0)
    $html_rating = "";

    //for rated stars
    for ($rcnt=0; $rcnt<$product_rating; $rcnt++) { 

          $html_rating .= "<i class='fa fa-star has-star' aria-hidden='true'></i>";


    //for not rated stars    
    for($star_blank=0; $star_blank < (5-$product_rating); $star_blank++)
          $html_rating .= "<i class='fa fa-star-o' aria-hidden='true'></i>";

     $returnData = $html_rating;

     return $returnData;

Leave a Reply

Your email address will not be published. Required fields are marked *