2+2

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

Post Reply
gg4000
Forum Newbie
Posts: 3
Joined: Mon Aug 01, 2011 7:09 pm

2+2

Post by gg4000 »

Hi

I'm trying to send 2+2 to a spreadsheet or anything to return a sum "4". or "2+2=4"
It's from a textbox in my calculator program. The textbox will contain the whole string "2+2"
I can add sum( or = within the program after a button click. I will also have multiply, divide, minus...etc.
The sheet will not be open. I just need to do the math as one input. ex. 2+2...

Any ideas?

Thank you
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: 2+2

Post by Apollo »

Try this: (note the preceding = character)

Code: Select all

=2+2
gg4000
Forum Newbie
Posts: 3
Joined: Mon Aug 01, 2011 7:09 pm

Re: 2+2

Post by gg4000 »

How and where to send it to be processed is my problem.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: 2+2

Post by Christopher »

So you want to parse strings like "2+2" or "3/4" or 5*6" and then calculate the result? I would recommend preg_match() or preg_split().
(#10850)
gg4000
Forum Newbie
Posts: 3
Joined: Mon Aug 01, 2011 7:09 pm

Re: 2+2

Post by gg4000 »

Right. I was able to split the text. But don't know what to do with it then. If I was able to put the number or numbers before the + into one hidden textbox and the number after the + into another, then I could process the two text boxes in my program. textbox1.text + textbox2.text.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: 2+2

Post by AbraCadaver »

Apollo wrote:Try this: (note the preceding = character)

Code: Select all

=2+2
If you are putting this in a spreadsheet then something like this after you have received the posted form:

Code: Select all

$calc = '=' . $_POST['formfieldname'];
Then put $calc in the spreadsheet cell. Or maybe I am totally misunderstanding?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: 2+2

Post by Christopher »

gg4000 wrote:Right. I was able to split the text. But don't know what to do with it then. If I was able to put the number or numbers before the + into one hidden textbox and the number after the + into another, then I could process the two text boxes in my program. textbox1.text + textbox2.text.
You will receive the text "2+2" as a string. When you split it you will have variables or an array like (array('2', '+', '2'). You will then need to walk through the array and do the computation based on the values and operators. It is a state machine.
(#10850)
Post Reply