Intelly XAD Posted September 3, 2006 Share Posted September 3, 2006 Hi there, i've created a function that generates variate sums, for example: 5 * 4 / 20 - 5 =This sum is saved under a string $sum="5 * 4 / 20 - 5 ="But now I want the PHP code to calculate this sum for met is there any function available in PHP that can do this?for example: calc($sum);Many thnx in advance for the answers Quote Link to comment Share on other sites More sharing options...
Barand Posted September 3, 2006 Share Posted September 3, 2006 try[code]<?phpeval('$sum = 5 * 4 / 20 - 5 ;');echo $sum;?>[/code]--> -4 Quote Link to comment Share on other sites More sharing options...
Intelly XAD Posted September 4, 2006 Author Share Posted September 4, 2006 Youre method works in the case you type it but when I type somthing like this it doesn't work:<?php$sum="5 + 20 / 5 - 4";eval('$sum = $sum;');?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 You are using single quotes. Variables dont work within single quotes. Use double quotes. Quote Link to comment Share on other sites More sharing options...
sasa Posted September 4, 2006 Share Posted September 4, 2006 try[code]<?php$sum="5 + 20 / 5 - 4";eval("\$sum = $sum;");echo $sum;?>[/code] Quote Link to comment Share on other sites More sharing options...
Intelly XAD Posted September 5, 2006 Author Share Posted September 5, 2006 Many thnx that worked... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.