Last active
December 19, 2018 10:40
-
-
Save ssovit/834090e4a618341a672584165fdf4fb5 to your computer and use it in GitHub Desktop.
Create FontAwesome static rating bar based on rating data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function createFontAwesomeStarRating($rating=0,$min=0,$max=10,$maxStars=5,$return=false){ | |
$score=(($rating - $min) * ($maxStars)) / ($max - $min) ; | |
$full=floor($score); | |
$half=ceil($score)-$full; | |
$empty=$maxStars-$full-$half; | |
$result='<div class="rating-stars" title="'.$score.'">'; | |
$result.=str_repeat('<i class="fa fa-star"></i>',$full); | |
$result.=str_repeat('<i class="fa fa-star-half-o"></i>',$half); | |
$result.=str_repeat('<i class="fa fa-star-o"></i>',$empty); | |
$result.="</div>"; | |
if($return){ | |
return $result; | |
} | |
echo $result; | |
} | |
createFontAwesomeStarRating(7,0,10,5,true); | |
// OR | |
$output=createFontAwesomeStarRating(7,0,10,5,false); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment