Download the PHP package simon-forb/php-formula-interpreter without Composer

On this page you can find all versions of the php package simon-forb/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 formula interpreter for php

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 :

Installing

Use Composer to install it:

How does it work ?

First, create an instance of FormulaInterpreter\Compiler

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

Finally run the formula from the executable :

Using operators

Operator multiplication (*) and division () are being evaluted first, then addition (+) and subtraction (-)

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

You can use as many parentheses as you like.

Comparison operators

Supported comparison operators are =, !=, <>, >=, >, <=, '<'.

Boolean operators

Supported boolean operators are AND and OR.

Future operators

Others operators like modulo, power, etc. will be implemented in the future as functions.

Using variables

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

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

Variables now supports dot . as the name.

String support

Variables can contain string. Use double quote (") for denote a string.

Using functions

Here is an example of expression using a function :

Available functions : pi, pow, cos, sin, sqrt & modulo

You can embed functions as much as you like

Custom functions

Now function can be added before compiling should you want to add more variables.

Listing parameters

You can get a list of all variables that must be provided to the run() method in order to run the executable:

This will output:


All versions of php-formula-interpreter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.0
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 simon-forb/php-formula-interpreter contains the following files

Loading the files please wait ....