2017 © Pedro Peláez
 

library expression-evaluator

Evaluate string expressions in PHP without eval() function

image

iserter/expression-evaluator

Evaluate string expressions in PHP without eval() function

  • Sunday, February 14, 2016
  • by serter
  • Repository
  • 3 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 20 % Grown

The README.md

Expression Evaluator

I looked around so much to find an expression evaluator, and none of my findings supported logical and comparison operators. I created this package from a gist I found. I will be writing a service provider for Laravel 5.1 soon., (*1)

Example Usage

$exEngine = new ExpressionEvaluator\Engine;, (*2)

echo $exEngine->evalute('5 + 3 * 2');, (*3)

// outputs 11, (*4)

Example evaluations

5 + 3 * 2, (*5)

11, (*6)

(1 > 2 AND 3 < 2) OR 1+2 == 3, (*7)

0, (*8)

(3 > 2) AND (3 < 5), (*9)

1, (*10)

(1 > 2) OR (3 < 5), (*11)

1, (*12)

(1 > 2) OR (6 > 5), (*13)

1, (*14)

(1 > 2) OR (6 < 5), (*15)

0, (*16)

1 + 2 == 3, (*17)

1, (*18)

2 < 1 + 2, (*19)

2, (*20)

(2 < 1) + 2, (*21)

2, (*22)

((2 < 1) + 2) == 2, (*23)

1, (*24)

-8/-2, (*25)

4, (*26)

-8/2, (*27)

-4, (*28)

-8/-2 + 15 * 1, (*29)

19, (*30)

Inspired by & developed upon https://gist.github.com/ircmaxell/1232629, (*31)

The Versions

14/02 2016

dev-master

9999999-dev

Evaluate string expressions in PHP without eval() function

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ilyas Serter