How can PHP be used to generate dynamic content on a website, such as user-specific greetings or automated image resizing?
To generate dynamic content on a website using PHP, you can utilize variables, conditional statements, and functions to create personalized greetings for users or automate tasks like image resizing. By embedding PHP code within your HTML files, you can dynamically generate content based on user input or other factors.
<?php
// Example 1: User-specific greetings
$userName = "John";
echo "Hello, $userName! Welcome back to our website.";
// Example 2: Automated image resizing
$imagePath = "image.jpg";
$newWidth = 200;
$newHeight = 150;
list($width, $height) = getimagesize($imagePath);
$newImage = imagecreatetruecolor($newWidth, $newHeight);
$oldImage = imagecreatefromjpeg($imagePath);
imagecopyresized($newImage, $oldImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagejpeg($newImage, "resized_image.jpg");
?>