https://github.com/mehralsnix/ext-tinyexpr
PHP TinyExpr Binding - Math evaluation for strings.
https://github.com/mehralsnix/ext-tinyexpr
c-bindings expression-evaluator php php-ext tinyexpr
Last synced: 4 months ago
JSON representation
PHP TinyExpr Binding - Math evaluation for strings.
- Host: GitHub
- URL: https://github.com/mehralsnix/ext-tinyexpr
- Owner: MehrAlsNix
- License: mit
- Created: 2020-03-14T19:55:00.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-22T22:21:29.000Z (almost 6 years ago)
- Last Synced: 2025-10-12T08:14:16.678Z (4 months ago)
- Topics: c-bindings, expression-evaluator, php, php-ext, tinyexpr
- Language: C
- Homepage: https://mehralsnix.github.io/ext-tinyexpr/
- Size: 49.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP TinyExpression
Math evaluation for strings.
[](https://travis-ci.com/MehrAlsNix/ext-tinyexpr) [](https://ci.appveyor.com/project/siad007/ext-tinyexpr)
## TinyExpr Binding
[TinyExpr](https://github.com/codeplea/tinyexpr) Bindings for PHP
> TinyExpr is a very small parser and evaluation library for evaluating math expressions from C
### Installation
#### Linux
```
git clone --branch "master" --depth 1 https://github.com/MehrAlsNix/ext-tinyexpr.git /tmp/tinyexpression
cd /tmp/tinyexpression
phpize
./configure
make
make install
echo "extension=tinyexpression.so" > /usr/local/etc/php/conf.d/tinyexpression.ini
```
#### Windows
tbd.
### Functions
#### tinyexpr_interp
(TinyExpression 0.1.0)
tinyexpr_interp - Evaluate math expressions from a `string`.
##### Description
```
tinyexpr_interp ( string $expr ) : float
```
##### Parameters
expr `string`
##### Return Values
Returns the evaluated math expression as a `float`.
##### Examples
```
docker-compose build
docker-compose up -d
docker-compose exec php bash
```
```
php -r "var_dump(tinyexpr_interp('2*9+8-(5/9)'));"
float(25.444444444444)
```
```
php -r "var_dump(tinyexpr_interp('sin(0.6)'));"
float(0.56464247339504)
```
Not parsable expressions will return `NAN`:
```
php -r "var_dump(tinyexpr_interp('(1+2'), is_nan(tinyexpr_interp('(1+2')));"
float(NAN)
bool(true)
```