Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
how to convert formula?
Old 12-14-2007, 02:13 AM how to convert formula?
Junior Talker

Posts: 3
Name: Adam Barczynski
Trades: 0
Hi!

I have problem with converting formula that I have as a string into formula that would give me result

f.e.
$formula="(A+B)";

and I have to get this to work f.e. like this:
replace A with 5 and B with 2 and then use it in
$c=$formula;
so $c in this example would be result of:
$c=(5+2);
$c=7;

any ideas?
Freyman2007 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-14-2007, 02:21 AM Re: how to convert formula?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
http://www.php.net/manual/en/language.functions.php
PHP Code:
function formula($a,$b){
  
$result=$a+$b;
  return 
$result;

__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-14-2007, 02:25 AM Re: how to convert formula?
Junior Talker

Posts: 3
Name: Adam Barczynski
Trades: 0
sorry, that's not it - the formula itself is INSIDE the string, so the example I wrote isn't exectly the function I will be working on

f.e. it will be something like T/4(D*D-H)
where T, D and H values are taken from other source
Freyman2007 is offline
Reply With Quote
View Public Profile
 
Old 12-14-2007, 05:47 AM Re: how to convert formula?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Then you'll have to resort either to eval() if the formula is not too complex
PHP Code:
//Be sure to have defined the value of T, and take care of precedences rules on $d*$d-$h.
//I would encapsulate them in () to be sure of that
eval("\$ret=T/4($d*$d-$h)");
echo 
$ret
or you will need to extract the datas from the string, and send them to a PHP rewritten formula.

PHP is not able to create a full formula out of a string representation.
You will have to rebuild it using PHP native functions.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-14-2007, 08:54 AM Re: how to convert formula?
Junior Talker

Posts: 3
Name: Adam Barczynski
Trades: 0
ok, thanx for the tipp
Freyman2007 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to how to convert formula?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15624 seconds with 12 queries