Page 2 of 2

Re: Performing number evaluations from input

Posted: Tue Jan 13, 2009 6:55 am
by johnny_control
jaoudestudios wrote:I would start by grabbing the inner 2 brackets with a regex and work outwards while keeping a running total. If this is looped it wont matter how many encapsulated brackets there are.
What would be the advantage of doing this over sanitizing input into eval(), using something like [0-9 \(\)\+\-\\\*]? And I do not have time right now to make an entire parser for this - are you aware of any premade classes?

Re: Performing number evaluations from input

Posted: Tue Jan 13, 2009 7:05 am
by jaoudestudios
johnny_control wrote:
jaoudestudios wrote:I would start by grabbing the inner 2 brackets with a regex and work outwards while keeping a running total. If this is looped it wont matter how many encapsulated brackets there are.
What would be the advantage of doing this over sanitizing input into eval(), using something like [0-9 \(\)\+\-\\\*]? And I do not have time right now to make an entire parser for this - are you aware of any premade classes?
I thought you were trying to write your own!?!

I did a google search and there are some php classes already written that also include scientific calculations.

If it is easier, like you said, just drop into the shell, but make sure you clean your variables.

Re: Performing number evaluations from input

Posted: Tue Jan 13, 2009 7:29 am
by johnny_control
jaoudestudios wrote:I thought you were trying to write your own!?!

I did a google search and there are some php classes already written that also include scientific calculations.

If it is easier, like you said, just drop into the shell, but make sure you clean your variables.
Not if there are premade scripts.

Hmm, I couldn't find any in Google. What search term did you use?

Thanks - I may do that for simplicity and for fewer bugs.

Re: Performing number evaluations from input

Posted: Tue Jan 13, 2009 8:05 am
by jaoudestudios
I am not suggesting write your own, all I was saying was that was the impression I got .

I searched for 'php calculator class'