Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leia em Português

⚛️ PHP Calculator

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.

⚙️ Technologies Used

  • 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: POST Forms and URL redirection (GET)
  • Interactivity: JavaScript (For the click sound and submission delay)

🚀 How to Run the Project

Since this project uses PHP, it requires a web server with PHP support to function.

1. Quick Test (PHP Built-in Server)

If you already have PHP installed, you can use its built-in web server for quick tests:

  1. Navigate to the project directory in your terminal.
  2. Execute the command:
    php -S localhost:8000
  3. Open your browser and access: http://localhost:8000

2. Local Environment (XAMPP, WAMP, MAMP)

  1. Download and install a local server package (XAMPP, WAMP, MAMP, etc.).
  2. Move the entire project folder (containing index.php, calcular.php, style.css, and the assets folders) to the server's document root directory (usually htdocs or www).
  3. Start the Apache server.
  4. Access the project through your browser (e.g., http://localhost/calculator/index.php).

📝 Calculator Usage

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.

Error Handling and Division by Zero

  • If the expression results in a division by zero (which in PHP generates INF or NAN), the result is displayed as 0 (or Error, depending on your final implementation).
  • If eval() encounters a syntax error or calculation failure, the display will show Error.

About

A simple calculator application built to practice PHP backend logic, form submission, and URL redirection.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages