This is a simple calculator project developed using PHP, HTML, and CSS, featuring a retro/pixelated design. It demonstrates the basic logic of a calculator by utilizing PHP for backend processing (via the eval() function) and communication between pages through URL redirection (header()).
Context: This project was developed based on knowledge and techniques learned in Web Programming classes, serving as a practical application of frontend (HTML/CSS/JS) and backend (PHP) concepts.
- Language: PHP (Calculation logic)
- Interface: HTML and CSS
- Font: The "Pixelade" typeface was used for the display. The font is Donationware, created by Astramat and downloaded via DaFont.
- Communication:
POSTForms and URL redirection (GET) - Interactivity: JavaScript (For the click sound and submission delay)
Since this project uses PHP, it requires a web server with PHP support to function.
If you already have PHP installed, you can use its built-in web server for quick tests:
- Navigate to the project directory in your terminal.
- Execute the command:
php -S localhost:8000
- Open your browser and access:
http://localhost:8000
- Download and install a local server package (XAMPP, WAMP, MAMP, etc.).
- Move the entire project folder (containing
index.php,calcular.php,style.css, and the assets folders) to the server's document root directory (usuallyhtdocsorwww). - Start the Apache server.
- Access the project through your browser (e.g.,
http://localhost/calculator/index.php).
The usage is intuitive, like any standard calculator, but here are some important details about the processing logic:
| Action | Value (name="acao") |
Processing Logic in calcular.php |
|---|---|---|
| Numbers (0-9, .) | 0 to 9, . |
Concatenates the value to the $expressao variable. |
| Operators (+, -, *, /) | +, -, *, / |
Concatenates the operator to $expressao. |
| Clear (C) | C |
Resets the expression and the result to 0. |
| Percentage (%) | % |
Divides the current number on the display by 100. |
| Invert Sign (±) | ± |
Multiplies the current value on the display by -1. |
| Equals (=) | = |
Executes the $expressao string using PHP's eval() function to get the final result. |
- If the expression results in a division by zero (which in PHP generates
INForNAN), the result is displayed as0(orError, depending on your final implementation). - If
eval()encounters a syntax error or calculation failure, the display will showError.