plugin:calc
Table of Contents
Calc Plugin
Description
- Lil calculator.
- All the PHP math functions and constants are allowed.
- French and English. Easy to add your own language.
Syntax
calc:[your_math_expression]=
→ resultcalc:[your_math_expression]>=
→ your_math_expression = result
Examples
calc:2+3*5=
→ 17calc:-1234.56*78.9=
→ -9,629.568calc:sin(pi()/4)=
→ 0.707106781187calc:round(exp(1),3)=
→ 2.718calc:(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 ! 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
plugin/calc.txt · Last modified: 2023-03-10 02:59 by 5.180.61.32