Created
February 15, 2018 11:29
-
-
Save flistefliste/6c5538819a2fd87d348ef6849211a9a7 to your computer and use it in GitHub Desktop.
Rate to fa-stars
This file contains hidden or 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 | |
/** | |
* Convert rate (ie. 3.5/5) into fontAwesome stars | |
* | |
* @param int $rate | |
* @return string | |
*/ | |
function getStars($rate){ | |
$max_rate = (int) 5 ; | |
$output = '<div class="widget-rating-stars">'; | |
for ($i=1; $i<=$max_rate; $i++) { | |
if ($i<=$rate) | |
$output .= '<i class="fa fa-star" aria-hidden="true"></i>'; | |
if (is_float($rate)) | |
{ | |
if( $i <= ceil($rate) && $i > floor($rate)) | |
{ | |
$output .= '<i class="fa fa-star-half-o" aria-hidden="true"></i>'; | |
} | |
} | |
if ($i > ceil($rate)) | |
$output .= '<i class="fa fa-star-o" aria-hidden="true"></i>'; | |
} | |
$output .='</div>'; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment