Download the PHP package mormat/php-formula-interpreter without Composer

On this page you can find all versions of the php package mormat/php-formula-interpreter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-formula-interpreter

php-formula-interpreter

A stand-alone php library for parsing and running formulas

Installation via composer

How does it work ?

First, create an instance of \Mormat\FormulaInterpreter\Compiler

Then use the compile()method to parse the formula you want to interpret. It will return an instance of \Mormat\FormulaInterpreter\Executable :

Finally run the formula from the executable :

Examples of formulas

Supported types in formulas

Numeric values

A numeric value can be an integer or a float

String values

Use simple quote to delimiter strings

Array values

Use comma to separate items and brackets to wrap the items

Functions, strings and operations can be used as an item of an array

Using operators

The following operators are available : operator usage description
+ a + b Sum of a and b.
- a - b Difference of a and b.
* a * b Product of a and b.
/ a / b Quotient of a and b.
in a in b If a is an array, checks if b is an item of a. If a is a string, checks if b is a substring of a

The operators *, \ are being evaluated first, then the operators + and -

You can also force the prioriry of an expression by using parentheses like this

You can use as many parentheses as you like.

Using variables

A variable is just a word inside your formula like this :

Just before executing a formula in PHP, make sure to inject all the required variables in an array

Using functions

Availables functions

name allowed types description
pi Get value of pi
cos numeric Cosine
sin numeric Sine
sqrt numeric Square root
pow numeric,numeric Exponential expression
modulo numeric,numeric Remainder of first value divided by second value
lowercase string Converts to a string lowercase
uppercase string Converts to a string uppercase
capitalize string Make a string's first character uppercase
count string\|array If value is an array, count the items in the array. If value is a string, count the characters in the string

How to register a custom function ?

Use the registerCustomFunction() method in the \Mormat\FormulaInterpreter\Compiler class.

The custom function must implement the \Mormat\FormulaInterpreter\Functions\FunctionInterface. This interface contains the methods below :

Why this library ?

Some user could wants to perform a simple calculation and being able to change it as much as he can. Before using a library, you could use the eval function. But this method has two major drawbacks :


All versions of php-formula-interpreter with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mormat/php-formula-interpreter contains the following files

Loading the files please wait ....