Giter Site home page Giter Site logo

samirkumardas / evaluate_math_string Goto Github PK

View Code? Open in Web Editor NEW
7.0 5.0 2.0 8 KB

A very simple PHP function that can evaluate math string without any other dependencies

PHP 100.00%
php math-string-expressions math-string-to-value math-eval eval-math math-eval-php eval-math-path evaluation-math-string math mathematics

evaluate_math_string's Introduction

evaluate_math_string

Since PHP create_function got deprecated as of PHP v7.2, we can no longer use that function to evaluate math string in the quickest way. I have created a very simple PHP function that can evaluate math strings without any other dependencies.

How to use?

Please check test.php

Example Expressions

Input Output
-3 -3
+5 5
5+2 7
-5-1 -6
5-1 4
2 + 2.5 + 3 / 3 + 3 * 3 14.5
5 + 10 /-2 - 5 *2 -10
((5 - 2.5) + 2) * ((5 - 2.5) + 2) 20.25
(((5 - 2.5) + 2) * ( 10 / 5)) 9
5-(-2) 7

Caveats

Please be noted that for the sake of simplicity, this function will not raise any errors in the case of the syntax problem. It will simply end up with zero or an ambiguous output. You must provide a valid syntax to get the correct result.

evaluate_math_string's People

Contributors

samirkumardas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.