我的默认页面在 php 中,我将 html 和 php
My default page is in php and I will the html and the php
我是一名年轻的开发者(15 岁)
我的网站出现问题。我的页面与 "localhost/sn/" 中的 html 和 php 不同步。通常,当我在浏览器中键入 "localhost/sn/" 时,我应该让 html 页面与 php 页面同步。但它不起作用。当我输入时,我只有 index.php 页面。
我的服务器是 XAMPP。
请帮助我!!!!!
如果您只想显示 html 页面,则不需要 xampp。如果你想用一些逻辑显示 html 页面,那么它必须是 index.php with template in html
如果您希望 运行 您的网站只有 html 和 css 结构,您可以使用扩展名为 html 的文件(e.x index.html) 当然你不需要使用 XAMPP.
如果您想 运行 您的网站并拥有 php 代码,请使用扩展名为 php (e.x index.php) 等的文件重要的是你需要把它放在 XAMPP.
的 htdocs 目录中
您可以做几件事。
首先,PHP 是一种编程语言,您可以将 PHP 代码和 HTML 输出混合在一起。有几个原因,为什么你不应该(所谓的意大利面条代码,见 here),但因为你刚刚开始,这似乎没问题。
另一方面,您可以使用 require
or include
.
将您的 HTML 整合到您的 PHP 中
当然,你既不喜欢一个也不喜欢另一个。您可以混合使用这两种方法(每个认真的 PHP 应用程序都会这样做)
混合 HTML 和 PHP
<?php
// We are in PHP country now
// Set the value of variable
$header = "My 1st header";
// This ends PHP country
?>
<!-- Now we are in HTML country -->
<h1><?= $header =></h1>
<?php
// PHP country again
// the character string `<?&= some_value ?>;`
// is a shortcut for `<?php echo some_value; ?>`
$count = 4;
for ($i = 0; $i < $count; $i++) {
echo "<p>Paragraph</p>";
}
这将输出 <h1>My 1st header</h><p>Paragraph</p><p>Paragraph</p><p>Paragraph</p><p>Paragraph</p>
在PHP
中包含HTML
这里有两个文件
index.php:
<?php
require "header.html";
echo "<p>Content</p>";
header.html
<h1>My 2nd header</h1>
在 XAMPP 中调用 index.php 将产生 <h1>My 2nd header</h1><p>Content</p>
您只需要 1 个文件{index.php},
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
<?php
echo ("Hello Arthur!");
?>
</head>
<body>
<div id="top">
asdfasdfsd
<div id="under">
asdfsadf
</div>
</div>
<!-- page content -->
</body>
</html>
然后,打开 Chrome 或您喜欢的任何浏览器,输入:
localhost/index.php
确保 {index.php} 文件在 htdocs 文件夹中并且 xampp Apache 已打开。
希望我帮到了你。
我是一名年轻的开发者(15 岁) 我的网站出现问题。我的页面与 "localhost/sn/" 中的 html 和 php 不同步。通常,当我在浏览器中键入 "localhost/sn/" 时,我应该让 html 页面与 php 页面同步。但它不起作用。当我输入时,我只有 index.php 页面。 我的服务器是 XAMPP。 请帮助我!!!!!
如果您只想显示 html 页面,则不需要 xampp。如果你想用一些逻辑显示 html 页面,那么它必须是 index.php with template in html
如果您希望 运行 您的网站只有 html 和 css 结构,您可以使用扩展名为 html 的文件(e.x index.html) 当然你不需要使用 XAMPP.
如果您想 运行 您的网站并拥有 php 代码,请使用扩展名为 php (e.x index.php) 等的文件重要的是你需要把它放在 XAMPP.
的 htdocs 目录中您可以做几件事。
首先,PHP 是一种编程语言,您可以将 PHP 代码和 HTML 输出混合在一起。有几个原因,为什么你不应该(所谓的意大利面条代码,见 here),但因为你刚刚开始,这似乎没问题。
另一方面,您可以使用 require
or include
.
当然,你既不喜欢一个也不喜欢另一个。您可以混合使用这两种方法(每个认真的 PHP 应用程序都会这样做)
混合 HTML 和 PHP
<?php
// We are in PHP country now
// Set the value of variable
$header = "My 1st header";
// This ends PHP country
?>
<!-- Now we are in HTML country -->
<h1><?= $header =></h1>
<?php
// PHP country again
// the character string `<?&= some_value ?>;`
// is a shortcut for `<?php echo some_value; ?>`
$count = 4;
for ($i = 0; $i < $count; $i++) {
echo "<p>Paragraph</p>";
}
这将输出 <h1>My 1st header</h><p>Paragraph</p><p>Paragraph</p><p>Paragraph</p><p>Paragraph</p>
在PHP
中包含HTML这里有两个文件
index.php:
<?php
require "header.html";
echo "<p>Content</p>";
header.html
<h1>My 2nd header</h1>
在 XAMPP 中调用 index.php 将产生 <h1>My 2nd header</h1><p>Content</p>
您只需要 1 个文件{index.php},
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="style.css">
<?php
echo ("Hello Arthur!");
?>
</head>
<body>
<div id="top">
asdfasdfsd
<div id="under">
asdfsadf
</div>
</div>
<!-- page content -->
</body>
</html>
然后,打开 Chrome 或您喜欢的任何浏览器,输入: localhost/index.php
确保 {index.php} 文件在 htdocs 文件夹中并且 xampp Apache 已打开。
希望我帮到了你。