Hakim
Hakim

Reputation: 97

call EvalMath to parse math expression

I'm new in php. I want to evaluate math expression using EvalMath class. I create new EvalMath using this code

require_once "evalmath.class.php";

$m = new EvalMath;

$result = $m->evaluate("2+2");

echo ($result);

instead of I get the result, I get the class content in my browser.

Did I miss something in my code?

Upvotes: 0

Views: 337

Answers (2)

Hakim
Hakim

Reputation: 97

EvalMath class use

<?

at first line instead of

<?php

and have no closing php tag. Add proper php tag:

<?php
class EvalMath{
....
}
?>

It will solve the problem.

Upvotes: 1

methai
methai

Reputation: 9133

This might sound stupid, but have you added PHP tags at the top of your file?

<?php
require_once "evalmath.class.php";
$m = new EvalMath;
$result = $m->evaluate("2+2");
echo ($result);
?>

Otherwise, I've tried your code and it works fine...

This project, FYI, looks promising. EvalMath seems to be over 8 years old at this point.

https://github.com/Riimu/Expresso

Upvotes: 0

Related Questions