Performing number evaluations from input

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

johnny_control
Forum Newbie
Posts: 16
Joined: Sat Dec 13, 2008 5:42 am

Re: Performing number evaluations from input

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Performing number evaluations from input

Post 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.
johnny_control
Forum Newbie
Posts: 16
Joined: Sat Dec 13, 2008 5:42 am

Re: Performing number evaluations from input

Post 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.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Performing number evaluations from input

Post 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'
Post Reply