PHPackages                             codryn/phpdice - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. codryn/phpdice

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

codryn/phpdice
==============

A comprehensive PHP library for parsing and rolling dice expressions for tabletop RPG systems

0.4.0(3mo ago)032↓100%[1 issues](https://github.com/codryn/phpdice/issues)MITPHPPHP &gt;=8.1CI failing

Since Jan 6Pushed 3mo agoCompare

[ Source](https://github.com/codryn/phpdice)[ Packagist](https://packagist.org/packages/codryn/phpdice)[ RSS](/packages/codryn-phpdice/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

PHPDice
=======

[](#phpdice)

[![PHP Version](https://camo.githubusercontent.com/27d7b4f926939f3cbfbdec4ee0bf45e33457aa351e1ceb3551eddc96c195e19d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312d2d382e352d626c75652e737667)](https://www.php.net/)[![PHPStan Level 10](https://camo.githubusercontent.com/d18b9a987aa81e64470a11caecf72caa66597c9ebd6b307bd1c2cb7a752b0dff/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e2e737667)](https://phpstan.org/)[![CI](https://github.com/codryn/phpdice/workflows/CI/badge.svg)](https://github.com/codryn/phpdice/actions)[![Latest Stable Version](https://camo.githubusercontent.com/e7afc4d6ef0e28660646e234fed64f47c9837de0cac706d581139e8dcf66a847/68747470733a2f2f706f7365722e707567782e6f72672f636f6472796e2f706870646963652f762f737461626c65)](https://packagist.org/packages/codryn/phpdice)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

> PHP library for parsing and rolling dice expressions for tabletop RPG systems.

**PHPDice** is a powerful and flexible library that allows developers to parse and roll complex dice expressions used in various tabletop role-playing games (RPGs). It supports a wide range of dice mechanics, including advantage/disadvantage, success counting, rerolls, exploding dice, critical hits, and more.

Features
--------

[](#features)

- **🎲 Universal Dice Notation**: Support for all major RPG systems (D&amp;D 5e, Pathfinder, Shadowrun, World of Darkness, FATE, Savage Worlds, etc.)
- **⚡ Advanced Mechanics**: Advantage/disadvantage, success counting, rerolls, exploding dice, critical detection, DC comparisons
- **📊 Statistical Analysis**: Pre-calculated min/max/expected values for any expression
- **🔧 Placeholder Variables**: Character sheet integration with `$variable$` syntax
- **➗ Complex Arithmetic**: Full expression evaluation with operator precedence and parentheses
- **❗ Error Handling**: Clear, specific error messages with location information
- **🚀 High Performance**: Parse &lt;100ms, Roll &lt;50ms for complex expressions
- **🔒 Type Safe**: Full PHP 8.1+ type declarations and strict mode
- **⚡ Zero Dependencies**: Pure PHP 8.1+ implementation using only stdlib and ctype extension
- **🧪 Well Tested**: Unit tests with comprehensive coverage
- **📦 PSR-12 Compliant**: Modern PHP coding standards

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- ctype PHP extension enabled

Installation
------------

[](#installation)

```
composer require codryn/phpdice
```

Quick Start and Usage
---------------------

[](#quick-start-and-usage)

```
