PHP code example of jes490 / dparser

1. Go to this page and download the library: Download jes490/dparser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jes490 / dparser example snippets


DParser::roll($expression);

//You can assess result of your expression like this:
DParser::roll($expression)->getResult();
//Or just use plain auto-conversion __toString()
DParser::roll('2+2'); //returns '4';

//You can access individual rolls like this:
DParser::roll('2d6')->getRolls(); //returns array of rolls results

DParser::roll('2d6+1d8+1d12+20');
DParser::roll('2+3*2-1+2d6-3*4');