在 PHP 中,可以使用各種方法動(dòng)態(tài)生成網(wǎng)頁(yè)內(nèi)容。以下是一些常見(jiàn)的方法:
<?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!");
?>
這些方法可以根據(jù)需要組合使用,以實(shí)現(xiàn)更復(fù)雜的動(dòng)態(tài)網(wǎng)頁(yè)內(nèi)容生成。