PHP Beginner

PHP Introduction and Setup

CodingerWeb
CodingerWeb
27 views 30 min read

Welcome to PHP Programming

PHP (PHP: Hypertext Preprocessor) is a popular server-side scripting language designed for web development. It powers over 75% of websites on the internet, including WordPress, Facebook, and Wikipedia.

What You'll Learn

  • What PHP is and why it's important
  • How to set up a PHP development environment
  • Writing your first PHP script
  • Understanding how PHP works with HTML

Setting Up PHP

To start coding in PHP, you need a web server with PHP installed. Here are your options:

Option 1: Local Development Environment

// Download and install XAMPP, WAMP, or MAMP
// These include Apache, MySQL, and PHP
// Start Apache and navigate to http://localhost

Option 2: Online PHP Playground

Use online editors like PHP Fiddle or 3v4l.org for quick testing.

Your First PHP Script

Create a file called hello.php:

<?php
// This is a PHP comment
echo "Hello, World!";
?>

PHP Tags

PHP code must be enclosed in PHP tags:

<?php
// Your PHP code here
?>

// Short tags (not recommended)
<? echo "Hello"; ?>

// Echo tags
<?= "Hello World" ?>

Mixing PHP with HTML

<!DOCTYPE html>
<html>
<head>
    <title>My First PHP Page</title>
</head>
<body>
    <h1><?php echo "Welcome to PHP!"; ?></h1>
    <p>Today is <?= date("Y-m-d") ?></p>
</body>
</html>

Practice Exercise

Create a PHP file that displays:

  • Your name
  • Current date and time
  • A welcome message

Key Takeaways

  • PHP is a server-side scripting language
  • PHP code runs on the server before sending HTML to the browser
  • Always use <?php ?> tags
  • PHP files must have a .php extension