在 PHP 中,可以使用各种方法动态生成网页内容。以下是一些常见的方法:
<?php
echo "Hello, World!";
print "Hello, World!";
?>
<?php
$name = "John";
$age = 30;
echo "My name is " . $name . " and I am " . $age . " years old.";
?>
<?php
$name = "John";
$age = 30;
echo <<<EOT
My name is $name and I am $age years old.
EOT;
?>
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Content</title>
</head>
<body>
<?php
$name = "John";
$age = 30;
?>
<p>My name is <?php echo $name; ?> and I am <?php echo $age; ?> years old.</p>
</body>
</html>
<?php
$fruits = array("apple", "banana", "cherry");
foreach ($fruits as $fruit) {
echo $fruit . "<br>";
}
?>
<?php
function display_message($message) {
echo $message;
}
display_message("Hello, World!");
?>
这些方法可以根据需要组合使用,以实现更复杂的动态网页内容生成。