选取 html 并包含到 php 页面
Picking up html and include into php page
我是 PHP 的业余爱好者。我正在编写一个名为 'index.php' 的文件,我将其内容放入一个名为 'Built.html'
的文件中
Index.php
<body>
<?php include 'built.html';?>
</body>
Built.html
<div id=mainContent>
<p>I love 'Hermione Granger.'</p>
</div>
我正在使用 xampp,然后转到 "Localhost/myfolder/index.php"(我的文件在这个文件夹中),我无法将从 html 文件中选取的内容保存到 index.php 文件。我做错了什么吗?
答案:
我搞定了。我认为 'Xampp' 主机存在一些问题。我重新启动它,并完成了文件。谢谢,"vihan" 提供了更多选项来将外部文件包含在我的 php 中。虽然,这与我的问题不太相关,但我很感激!
不确定您得到的究竟是什么,iframe 可能更直接。如果您只是想获取文本或其他内容,请不要使用它:
<div id="mainContent">
<iframe src="built.html"></iframe>
</div>
php
PHP,您可能需要确保路径确实正确:
include __DIR__ + '/built.html';
此外,我知道这对某些人有效:
include('built.html');
或者 JavaScript:
var xhr = (new window.XMLHttpRequest() || new window.ActiveXObject("Microsoft.XMLHTTP"));
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
document.getElementById('mainContent').innerHTML = xhr.responseText;
}
};
xhr.open('GET', 'built.html', false);
xhr.send();
我是 PHP 的业余爱好者。我正在编写一个名为 'index.php' 的文件,我将其内容放入一个名为 'Built.html'
的文件中Index.php
<body>
<?php include 'built.html';?>
</body>
Built.html
<div id=mainContent>
<p>I love 'Hermione Granger.'</p>
</div>
我正在使用 xampp,然后转到 "Localhost/myfolder/index.php"(我的文件在这个文件夹中),我无法将从 html 文件中选取的内容保存到 index.php 文件。我做错了什么吗?
答案:
我搞定了。我认为 'Xampp' 主机存在一些问题。我重新启动它,并完成了文件。谢谢,"vihan" 提供了更多选项来将外部文件包含在我的 php 中。虽然,这与我的问题不太相关,但我很感激!
不确定您得到的究竟是什么,iframe 可能更直接。如果您只是想获取文本或其他内容,请不要使用它:
<div id="mainContent">
<iframe src="built.html"></iframe>
</div>
php
PHP,您可能需要确保路径确实正确:
include __DIR__ + '/built.html';
此外,我知道这对某些人有效:
include('built.html');
或者 JavaScript:
var xhr = (new window.XMLHttpRequest() || new window.ActiveXObject("Microsoft.XMLHTTP"));
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
document.getElementById('mainContent').innerHTML = xhr.responseText;
}
};
xhr.open('GET', 'built.html', false);
xhr.send();