PHP Classes
elePHPant
Icontem

PHP Math Formula Parser: Parse and evaluate formulas with variables

Recommend this page to a friend!
  Info   View files Documentation   View files View files (25)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-01-24 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
formula 0.3.0Custom (specified...7.1Math, Parsers, PHP 7
Description Author

This package can parse and evaluate formulas with variables.

It can take a string with a math expression and parses it so it can be evaluated replacing variables in the expression by given values.

The packages supports operations like addition, subtraction, multiplication and division.

Name: Walk <contact>
Classes: 1 package by
Country: Ukraine Ukraine

Details

formula

Latest Stable Version Build Status Total Downloads

Simple mathematical expression parser

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist seregas/formula "*"

or add

"seregas/formula": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

$parser = new \socialist\formula\Formula('2 + 3 * 2,65 + 25 - 26');
$parser->calculate(); // 8.95

Also in the formula you can use variables:


$parser = new \socialist\formula\Formula('2 + 3 * p + 25 - 26');
$parser->setVariable('p', 2,65);
$parser->calculate(); // 8.95

And insert comments like /.../, [...] or {...}:


$parser = new \socialist\formula\Formula('2 + 3 p / price */ + 25 - 26');
$parser->setVariable('p', 2,65);
$parser->calculate(); // 8.95

  Files folder image Files  
File Role Description
Files folder imagesrc (3 files, 2 directories)
Files folder imagetests (5 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageexpression (5 files)
Files folder imageoperator (5 files)
  Plain text file ExpressionFactory.php Class Class source
  Plain text file ExpressionNotFoundException.php Class Class source
  Plain text file Formula.php Class Class source

  Files folder image Files  /  src  /  expression  
File Role Description
  Plain text file Division.php Class Class source
  Plain text file Increment.php Class Class source
  Plain text file Multiplication.php Class Class source
  Plain text file Operator.php Class Class source
  Plain text file Subtraction.php Class Class source

  Files folder image Files  /  src  /  operator  
File Role Description
  Plain text file Double.php Class Class source
  Plain text file Expression.php Class Class source
  Plain text file Integer.php Class Class source
  Plain text file Percent.php Class Class source
  Plain text file Variable.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageoperator (1 file)
  Plain text file DoubleTest.php Class Class source
  Plain text file FormulaTest.php Class Class source
  Plain text file IntegerTest.php Class Class source
  Plain text file PersentTest.php Class Class source
  Plain text file VariableTest.php Class Class source

  Files folder image Files  /  tests  /  operator  
File Role Description
  Plain text file OperatorTest.php Class Class source

 Version Control Unique User Downloads  
 100%
Total:0
This week:0