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
2+2
Moderator: General Moderators
Re: 2+2
Try this: (note the preceding = character)
Code: Select all
=2+2- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: 2+2
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)
Re: 2+2
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.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: 2+2
If you are putting this in a spreadsheet then something like this after you have received the posted form:Apollo wrote:Try this: (note the preceding = character)Code: Select all
=2+2
Code: Select all
$calc = '=' . $_POST['formfieldname'];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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: 2+2
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.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.
(#10850)