PHP Examples

PHP syntax highlighting

PHP Syntax Highlighting

<!DOCTYPE html> <html> <head> <title><?php echo $pageTitle; ?></title> </head> <body> <h1>Welcome to My Site</h1> <?php // User information $userName = "John Doe"; $userAge = 30; function greetUser($name) { return "Hello, " . $name . "!"; } ?> <div class="user-info"> <p><?php echo greetUser($userName); ?></p> <p>Age: <?php echo $userAge; ?></p> </div> <ul> <?php $items = array("Apple", "Banana", "Orange"); foreach ($items as $item) { echo "<li>$item</li>\n"; } ?> </ul> <?php if ($userAge >= 18): ?> <p>You are an adult.</p> <?php else: ?> <p>You are a minor.</p> <?php endif; ?> <table> <tr> <th>Name</th> <th>Value</th> </tr> <?php for ($i = 1; $i <= 5; $i++) { echo "<tr>"; echo "<td>Item $i</td>"; echo "<td>" . ($i * 10) . "</td>"; echo "</tr>"; } ?> </table> <? // Short PHP tags $shortTag = "This uses short tags"; echo $shortTag; ?> <footer> <p>Copyright <?php echo date('Y'); ?></p> </footer> </body> </html>