PHP Classes

PHP Utilities: Evaluate math expressions, PHP templates, etc..

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 139 All time: 9,184 This week: 154Up
Version License PHP version Categories
php-utilities 1.0.0BSD License5.6PHP 5, Language, Parsers
Description 

Author

This class can evaluate math expressions, PHP templates, command line parameters, and parse PHP.

It can take a string with a math expression and evaluate it to compute the result value.

The class can also take template data string and find PHP code it may contains to replace by its output.

It can also parse a string with command line interface parameters and replace them by their parameter values.

The class can also parse PHP code and extract its tokens.

Innovation Award
PHP Programming Innovation award winner
February 2017
Winner
PHP is very well known for being a template language. It can automatically process the output of a template script and combine with the output of the PHP code contained in the template.

However, there are some cases on which you may extract only the output of the code in the template and process it separately. This class provides means to achieve exactly that, so the script output can be evaluated in a different context of the current scope.

The class also provides other features that overcome PHP limitations.

Manuel Lemos
Picture of Christian Vigh
  Performance   Level  
Name: Christian Vigh <contact>
Classes: 32 packages by
Country: France France
Age: 57
All time rank: 13810 in France France
Week rank: 10 Up1 in France France Up
Innovation award
Innovation award
Nominee: 20x

Winner: 3x

Example

<?php
   
/****************************************************************************************************

        This example demonstrates the use of the EvaluateExpression() method, using different
        expressions, valid or not.

     ****************************************************************************************************/
   
    
require_once ( '../PhpUtilities.phpclass' ) ;

     if (
php_sapi_name ( ) != 'cli' )
        echo (
'<pre>' ) ;

   
$expressions = array
       (
       
'17 * 4', // no error
       
'99*', // generates a fatal error
       
'4 * 32', // no error
       
'UNDEFINED_CONSTANT * 12' // generates a notice message
       
) ;

    echo
"Evaluation results :\n" ;
    echo
"------------------\n" ;
   
    foreach (
$expressions as $expression )
       {
        echo
sprintf ( "%-24s", $expression ) . " : " ;

       
$status = PhpUtilities::EvaluateExpression ( $expression, $result, $error ) ;

       
// Returned status is true : the expression evaluated correctly
       
if ( $status )
            echo
$result ;
       
// Status = false : the expression generated a fatal error (such as parsing error) or notice/error message
        // In this case, the error message is available in the supplied $error variable
       
else
            echo
"(error) $error" ;

        echo
"\n" ;
        }


  Files folder image Files  
File Role Description
Files folder imageexamples (3 files)
Plain text file PhpUtilities.phpclass Class Class source
Accessible without login Plain text file README.md Doc. Documentation
Plain text file Regex.class.php Class Class source

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file evaluateexpression.ini Data Auxiliary data
  Accessible without login Plain text file evaluateexpression.php Example Example script
  Accessible without login Plain text file evaluatetags.php Example Example script

Downloadphp-utilities-2016-11-25.zip 29KB
Downloadphp-utilities-2016-11-25.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
PHP Regex Advanced Download .zip .tar.gz Required Required
 Version Control Unique User Downloads Download Rankings  
 100%
Total:139
This week:0
All time:9,184
This week:154Up