How can PHP be used to display specific content based on different URL parameters?
To display specific content based on different 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 parameter values.
<?php
// Retrieve the URL parameter
$param = $_GET['param'];
// Use conditional statements to display specific content based on the parameter
if ($param == 'option1') {
echo "Content for option 1";
} elseif ($param == 'option2') {
echo "Content for option 2";
} else {
echo "Default content";
}
?>
Related Questions
- In what situations would using sessions be preferable over hidden fields for preserving form data in PHP?
- What are some best practices for using error_reporting(E_STRICT) in PHP development to catch errors early on?
- How can PDO attributes like PDO::ATTR_ORACLE_NULLS and PDO::NULL_TO_STRING affect JSON encoding and data integrity?