返回值php

返回值php,php,Php,我从return语句(基于JS)中所知道的就是停止脚本的执行并返回值以及忽略后的内容,那么这怎么可能呢 (事实上是必需的)在这段php代码中: <?php return "<!DOCTYPE html> <html> <head> <title>$title</title> <meta http-equiv='Content-Type' content='text/html;charset=utf-8'/> </

我从return语句(基于JS)中所知道的就是停止脚本的执行并返回值以及忽略后的内容,那么这怎么可能呢 (事实上是必需的)在这段php代码中:

<?php
return "<!DOCTYPE html>
<html>
<head>
<title>$title</title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>
</head>
<body>
$content
</body>
</html>";

你就快到了

使用template/page.php,您不需要运行返回,只需执行以下操作:

<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>
</head>
<body>
<?php echo $content; ?>
</body>
</html>
Include将从您通常包含的文件中提取所有信息


只要您需要php文件,就可以从任何地方提取信息。PDO/OOP是如何做到这一点的一个很好的例子,我强烈建议你多学一点,以实现你想做的事情(从我在问题中的理解)。

非常感谢,我想我会同意你的方法,这种回报真的令人困惑
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>
</head>
<body>
<?php echo $content; ?>
</body>
</html>
<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
$title = "Test title";
$content = "<h1>Hello World</h1>";
include_once "templates.php";