Want to add 5-star ratings to your website or app without bloated dependencies or framework lock-in? Meet sim-rating — a simple, customizable PHP library for calculating and rendering 5-star ratings in multiple formats.
Why Choose sim-rating?
- Works with any php Framework – Use it with plain PHP, Laravel, CodeIgniter, Symfony, or any PHP setup.
- Lightweight – Just clean, efficient PHP.
- Fully Customization – Adjust colors, styles, formats, and more.
- Built-in Smart Logic – Auto-calculate totals, averages, and percentage distributions.
Getting Started
Installation
composer require emleons/sim-rating
Basic Example
require('vendor/autoload.php');
use Emleons\SimRating\Rating;
$ratings = [
'one_star' => 10,
'two_star' => 20,
'three_star' => 30,
'four_star' => 40,
'five_star' => 50
];
$rating = new Rating($ratings);
echo $rating->render('html'); // Outputs HTML star rating
echo $rating->render('json'); // Outputs JSON
🎨 Customization Options
echo $rating->render('html', [
'type' => 'bars', // 'stars' or 'bars'
'color' => '#4a90e2', // Custom color
'bar_height' => '25px',
'show_summary' => true
]);
✨ Features at a Glance
1. Multiple Display Modes
- Stars (default)
- Bars (horizontal progress bars)
- JSON (great for APIs)
2. 🧠 Built-In Rating Calculations
$rating->getAverage(); // 3.67
$rating->getTotal(); // 150
$rating->getDistribution(); // ['five_star' => 33.33, ...]
3. 🧩 Framework-Friendly
Laravel Blade
@php
$rating = new \Emleons\SimRating\Rating($product->ratings);
@endphp
{!! $rating->render() !!}
CodeIgniter 4
// Controller
$rating = new \Emleons\SimRating\Rating($product['ratings']);
return view('product_view', ['rating' => $rating->render()]);
// View
<?= $rating ?>
⚙️ Advanced Usage
🛠️ Custom Template Support
echo $rating->render('html', [
'template' => 'views/custom-rating-template.php'
]);
🌟 Enable Interactive Ratings
echo $rating->render('html', [
'interactive' => true // Adds clickable stars (requires JS)
]);
🔗 Useful Links
- 📦 Packagist: emleons/sim-rating
- 🐙 GitHub: github.com/emleonstz/sim-rating
🎁 Tip: Whether you’re building an e-commerce store, course platform, or review website, sim-rating helps you show user feedback with clean, minimal code.
Top comments (3)
While I think it is a good effort, there are a few things that could change.
Remove the vendor folder from the library and add the dependencies in the composer.json file. This will make it easier to prevent version conflicts.
Move html and css out of the
HtmlRenderer
this will make it easier to overwrite those assets.The
SVGRenderer
doesn't render an svg, it returns json. I would remove that renderer.Use data objects and enums to move data around and identify parts of the functionality. It will give the library a better foundation.
Thanks I will update.
Good work but javascript invented im sorry.