关于在PHP中包含html页面的问题 [英] Question about including html page in PHP

查看:72
本文介绍了关于在PHP中包含html页面的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在PHP页面(比如index.php)中包含一个HTML页面,并且包含以下内容:

 < ?php 
include(../../forms/login/form.html);
?>

然后将form.php正确显示在index.php中?当我说得对,我的意思是所有的图像和CSS。



我问的原因是因为我的情况并非如此。我试了一下,它会显示form.html,但没有任何样式...

任何帮助将不胜感激,谢谢!



更新:






目前,我在forms.html中有以下内容:

 < link href =view.cssmedia =all =stylesheettype =text / css/> ; 
< script src =view.jstype =text / javascript>< / script>
< link href =../../ css / style.css =stylesheettype =text / css/>

现在,forms.html可以正确显示。



在index.php上,我有:

 < head> 
< meta content =text / html; charset = utf-8http-equiv =Content-Type/>
< title> UofS :: Residence Life Management System< / title>
< link href =css / style.css =stylesheettype =text / css/>

< / head>

< body>

<?php
include(html / header.html);
?>

<?php
include(php / navigation.php);
?>
< br>< / br>
<?php
include(forms / login / form.html);
?>
< br>< / br>
<?php
include(html / footer.html);
?>

< / body>

< / html>

forms.html的唯一参考是通过php include()。没有指向它的样式表。这是不正确加载forms.html的页面。这是不对的?



谢谢!

解决方案

你的样式表可能是相对的。它将需要相对于浏览器中的url(index.php)。或者使它成为一个绝对路径。

自更新以来进行编辑:
view.css和view.js不会被加载,因为它们的路径是相对的。使这些路径绝对或相对index.php页面。只要从任何地方包含form.html,使它们绝对会使它们工作。从index.php创建相对路径将使它们在从那里被包含时工作,但是当从其他目录包含时不会被使用。

更好的是,如果你知道你需要加载这些文件,把链接放在index.php页面上,而不是form.html页面。



另外请注意,您可以使用以网站根目录开头的路径,您不必包含主机和域名:

 < link href =/ css / style.css rel =stylesheettype =text / css/> 

在css / style.css之前的斜杠会使这个绝对路径适用于您的live和dev服务器。

编辑...



假设你的index.php文件位于根目录

 < link href =/ forms / login / view.cssmedia = all =stylesheettype =text / css/> 
< script src =/ forms / login / view.jstype =text / javascript>< / script>
< link href =/ css / style.css =stylesheettype =text / css/>


If I include an HTML page on a PHP page (say, index.php) with the following:

<?php
include ("../../forms/login/form.html");
?>

Then will form.php show up correctly in index.php? When I say correctly, I mean with all of its images and CSS.

The reason I am asking is because that's not the case with me. I tried it out, and it will show the form.html but without any styling...

Any help would be appreciated, thanks!

UPDATE:


Currently, I have the following on forms.html:

<link href="view.css" media="all" rel="stylesheet" type="text/css" />
<script src="view.js" type="text/javascript"></script>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />

Now, forms.html displays correctly by itself.

On index.php, I have:

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>UofS :: Residence Life Management System</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?php
include ("html/header.html");
?>

<?php
include ("php/navigation.php");
?>
<br></br>
<?php
include ("forms/login/form.html");
?>
<br></br>
<?php
include ("html/footer.html");
?>

</body>

</html>

The only reference to forms.html is through the php include(). There is no stylesheet pointing to it. This is the page that does not load forms.html correctly. Is this not right?

Thanks!

解决方案

The path to your style sheet is probably relative. It will need to be relative to the url in the browser (index.php). Or make it an absolute path.

Edit since your update: view.css and view.js will not be loaded because their paths are relative. Make those paths absolute or relative from the index.php page. Making them absolute will make them work whenever form.html is included from anywhere. Making the paths relative from index.php will make them work when included from there, but not when included from other directories.

Better yet, if you know you need to load those files, put the links on the index.php page and not the form.html page.

Also note that you can use paths that start with the root of your site, you do not have to include the host and domain name:

<link href="/css/style.css" rel="stylesheet" type="text/css" />

The slash before "css/style.css" will make that an absolute path that will work on your live and dev servers.

Edit...

Assuming that your index.php file is at the root level, try this in forms.html:

<link href="/forms/login/view.css" media="all" rel="stylesheet" type="text/css" />
<script src="/forms/login/view.js" type="text/javascript"></script>
<link href="/css/style.css" rel="stylesheet" type="text/css" />

这篇关于关于在PHP中包含html页面的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆