How can PHP be used to dynamically display content based on URL parameters?
To dynamically display content based on URL parameters in PHP, you can use the $_GET superglobal array to retrieve the parameters from the URL and then use conditional statements to determine which content to display based on the parameters.
<?php
// Retrieve the URL parameter
$param = $_GET['param'];
// Use conditional statements to display content based on the parameter
if($param == 'value1') {
echo "Content for value1";
} elseif($param == 'value2') {
echo "Content for value2";
} else {
echo "Default content";
}
?>
Related Questions
- How can PHPMailer be used to prevent header injection in email forms?
- What are the differences between using fetchAll() with count() and rowCount() with PDO Prepared Statements in PHP?
- How can you securely store and manage survey responses in PHP to prevent duplicate submissions and ensure data integrity?