PHPackages                             jcubic/expression - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. jcubic/expression

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

jcubic/expression
=================

Safely evaluate math, string, and boolean expressions

2.0.0(2y ago)35.8k—5.7%3[2 issues](https://github.com/jcubic/expression.php/issues)MITPHPCI passing

Since Oct 7Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/jcubic/expression.php)[ Packagist](https://packagist.org/packages/jcubic/expression)[ RSS](/packages/jcubic-expression/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (6)Used By (0)

 [![Expression.php - safely evaluate math, string, and boolean expressions](https://github.com/jcubic/expression.php/raw/master/.github/logo.svg?raw=true)](https://github.com/jcubic/expression.php/blob/master/.github/logo.svg?raw=true)
===========================================================================================================================================================================================================================================

[](#--)

[Safely evaluate math, string, and boolean expressions](https://github.com/jcubic/expression.php/)

[![Latest Stable Version](https://camo.githubusercontent.com/32d7859c24cd1596731338ce23b3cff1408e1e4cde5b5ab4207cc2153b7d99a0/68747470733a2f2f706f7365722e707567782e6f72672f6a63756269632f65787072657373696f6e2f762f737461626c652e737667)](https://packagist.org/packages/jcubic/expression)[![CI](https://github.com/jcubic/expression.php/actions/workflows/test.yaml/badge.svg)](https://github.com/jcubic/expression.php/actions/workflows/test.yaml)[![Total Downloads](https://camo.githubusercontent.com/e972e64892f6a8aa0c06a41a17532b082b580ba375f366476d0bf48f0f574efa/68747470733a2f2f706f7365722e707567782e6f72672f6a63756269632f65787072657373696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/jcubic/expression)[![License](https://camo.githubusercontent.com/bd3320445fac79fa7705a60520c13dedfe7a6e67dcbc3b7e730e4df1fdd1d26f/68747470733a2f2f706f7365722e707567782e6f72672f6a63756269632f65787072657373696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/jcubic/expression)

DEMO
----

[](#demo)

Check [Online REPL](https://expression.jcubic.pl/) to test the library. The source code of the Demo is located in [www directory](https://github.com/jcubic/expression.php/tree/master/www/).

DESCRIPTION
-----------

[](#description)

Use the Expression class when you want to evaluate mathematical or boolean expressions from untrusted sources. You can define your own variables and functions, which are stored in the object.

FEATURES
--------

[](#features)

- Integers and floats
- Math Expressions: `*` `/` `-` `+` `%`, `^`, and `**`
- Boolean Expression: `&&`, `||`, and `!`
- Comparisons: `>` `>` `
