该扩展将帮助我们有效地编写PHP代码,并在出现错误时进行调试。
打开 XAMPP 控制面板后,启动 APACHE Web 服务器,因为我们需要它在浏览器中查看 PHP 文件。
编写 PHP 代码或将其复制粘贴到文件中。保存文件 – Ctrl+S。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Example</title>
<style>
body {
background-color: #f4f4f4; /* Set the background color */
font-family: 'Arial', sans-serif; /* Set the font family */
color: #333; /* Set the text color */
margin: 20px; /* Add some margin for better visibility */
}
h1 {
color: #007BFF; /* Set a different color for the heading */
}
</style>
</head>
<body>
<?php
// PHP code starts here
// Display a greeting message
echo "<h1>Hello, PHP!</h1>";
// Get the current date and time
$currentDate = date("Y-m-d H:i:s");
// Display the current date and time
echo "<p>Current Server Date and Time: $currentDate</p>";
// PHP code ends here
?>
</body>
</html>
http://localhost/myproject/myfirstphp.php
您应该会在浏览器中看到 PHP 代码的输出。