Page 1 of 1

Simple addition issue in PHP

Posted: Fri Oct 25, 2013 9:40 am
by soupi
I am trying to learn PHP, how would I start this?

Given an input of an expression consisting of a string of letters and operators (plus sign, minus sign, and letters. IE: ‘b-d+e-f’) and a file with a set of variable/value pairs separated by commas (i.e: a=1,b=7,c=3,d=14) write a program that would output the result of the inputted expression.

For example, if the expression input was ("a + b+c -d") and the file input was ( a=1,b=7,c=3,d=14) the output would be -3.

i know how to do it in JAVA but am stumped on PHP

Thank you guys

Re: Simple addition issue in PHP

Posted: Fri Oct 25, 2013 4:42 pm
by Christopher
There are a number of ways to parse the string and get the tokens and operands. There are a number of ways to parse the key/value pairs. At at a high level, how would you do it in Java?

Re: Simple addition issue in PHP

Posted: Mon Oct 28, 2013 2:40 pm
by AbraCadaver
soupi wrote:I am trying to learn PHP, how would I start this?

Given an input of an expression consisting of a string of letters and operators (plus sign, minus sign, and letters. IE: ‘b-d+e-f’) and a file with a set of variable/value pairs separated by commas (i.e: a=1,b=7,c=3,d=14) write a program that would output the result of the inputted expression.

For example, if the expression input was ("a + b+c -d") and the file input was ( a=1,b=7,c=3,d=14) the output would be -3.

i know how to do it in JAVA but am stumped on PHP

Thank you guys
Homework?