>
Trying to split a string in 3 variables, but a lit...
Welcome, Guest

by prabhat on Saturday, 15 January 2011
Trying to split a string in 3 variables, but a little more tricky - PHP


Having pretty much covered the basics in PHP, I decided to challenge myself and make a simple calculator. After some attempts I figured it out, but I'm not entirely content with it. I want to make it more user friendly and have the calculator input in just one box, very much like google search.

So one would simply type: 5+2 and recieve 7.

How would I split the string "5+2" into three variables so that the math functions can convert the numbers into integers and recognize the operator, as well as accounting for the possibility of someone using spaces between the values as well?

Would you explode the string? But what would you explode it with if there are no spaces? I've also stumbled upon the preg_split function, but I can't seem to wrap my head around or know if it's suitable to solve this problemt. What method would be the best option for this?


Topic Normal Re: Trying to split a string in 3 variables, but a little more tricky - PHP
by nik on 02/04/2011 19:51

U can use '+' to explode the two variables in this case..

with more than one operator case use +,-,/ etc operators to explode and calculate(when no operator is in between), one can search in-between operators and explode the string..

�Whatever u do, building calculator with php(Server side scripting language) is a bad idea. One can use Javascript or its library which throw the result fast for these programs.

If still want to proceed with php, ajax is what we can use and instead of taking full expression(52+3) we can built a logic for taking one thing at a time (take 54, then take + and then take 3(calculate here))

 



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering