====== Calc Plugin ====== ---- plugin ---- description: Petite calculatrice / Lil calculator author : Etienne M. email : emauvaisfr@yahoo.fr type : syntax lastupdate : 2008-09-11 compatible : 2008-05-05 depends : conflicts : similar : tags : calculation, math downloadurl: http://emauvaisfr.free.fr/dokuwiki/calc.tar.gz bugtracker : sourcerepo : donationurl: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=79ZVTRTJ52DDY&lc=FR&item_name=Plugin%20dokuwiki%20%28Etienne%20M%2e%29¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted ---- ===== Description ===== * Lil calculator. * All the [[http://www.php.net/math |PHP math functions and constants]] are allowed. * French and English. Easy to add your own language. ===== Syntax ===== * ''calc:[your_math_expression]='' -> result * ''calc:[your_math_expression]>='' -> your_math_expression = result ===== Examples ===== * ''calc:2+3*5='' -> 17 * ''calc:-1234.56*78.9='' -> -9,629.568 * ''calc:sin(pi()/4)='' -> 0.707106781187 * ''calc:round(exp(1),3)='' -> 2.718 * ''calc:(1+sqrt(5))/2='' -> 1.61803398875 * You can display the expression before the result adding a ">" before the "=" * ''calc:2+3*5>='' -> 2+3*5 = 17 * The plugin handles errors * ''calc:5/0='' -> "**Calc error:** Division by zero" * ''calc:sqrt(-1)='' -> "Bad value..." * ''calc:unauthorized_function(12)='' -> "**Calc error:** syntax error, unexpected ';'" ===== Tips ===== * You can customize your decimal and thousand separators in the lang/xx/lang.php file (xx is your language code: fr, en...). * A comment is added in the source code of the page before the calculation: you can see what expression has really been processed by the plugin. * You can also use this plugin to format a single number. Ex: ''calc:1234567890='' -> 1,234,567,890. ===== Security ===== * This plugin uses the PHP eval() function, but it removes all functions that are not mathematical functions before doing the eval(). * It also removes every ";" and "$" char before doing the evaluation. * **Tell me if you see a security break using this plugin.** ===== Version history ===== * 2008-09-08: first one! * 2008-09-10: doesn't try to format string results (like those sent by base_convert) * 2008-09-11: prevents XSS ===== Discussion ===== * Tell me... ---- I dreamed about it, and you made it. Thank you so much ! //[[mailto:neibaf@gmail.com|fab]]// ---- > You're welcome ;-) ---- I get an error: ''Parse error: syntax error, unexpected '{' in /dokuwiki/lib/plugins/calc/syntax.php on line 118'':-( ---- Works like a charm. Thank you so much. //Henning//