这是一个关键场景。我有2页,例如
output.php has dynamic table data with style which is get from excel.
<?php
ob_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';
/* EXCEL TABLE */
$inputFileName2 = 'C:\inetpub\wwwroot\Monthly-EDM\Action_items.xlsx';
try {
$objPHPExcel1 = PHPExcel_IOFactory::load($inputFileName2);
}
catch (Exception $e) {
die('Error loading file "' . pathinfo($inputFileName2, PATHINFO_BASENAME) . '": ' . $e->getMessage());
}
/* Open an Excel & count */
$allDataInSheet = $objPHPExcel1->getActiveSheet()->toArray(null, true, true, true);
$arrayCount = count($allDataInSheet); // Here get total count of row in that Excel sheet
$file = fopen($inputFileName2, "r");
fclose($file);
echo '<table width="800" border="0" cellspacing="0" cellpadding="0" align="center">';
echo '<tr>';
echo '</td>';
/* <th> code here */
echo '</td>';
echo ' </tr>';
echo ' <!-- Header blue row - end -->';
echo '<style>.shiva:nth-child(odd) { background-color:#b9b8bb; }</style>';
echo '<style>.shiva:nth-child(even) { background-color:#e5e8e8; }</style>';
for ($i = 2; $i <= $arrayCount; $i++) {
$_SESSION["a"] = trim($allDataInSheet[$i]["A"]);
$_SESSION["b"] = trim($allDataInSheet[$i]["B"]);
$_SESSION["c"] = trim($allDataInSheet[$i]["C"]);
$_SESSION["d"] = trim($allDataInSheet[$i]["D"]);
$_SESSION["e"] = trim($allDataInSheet[$i]["E"]);
$_SESSION["f"] = trim($allDataInSheet[$i]["F"]);
$_SESSION["g"] = trim($allDataInSheet[$i]["G"]);
echo ' <tr>';
echo '<td>';
echo '</td>';
echo ' </tr>';
}
echo '<!-- table content - end --> ';
echo '</table>';
echo '</td>';
echo ' </tr>';
echo '</table>';
?>
get.html (I want to get the output of output.php here)
Click to view the result of the output.php
如何获取output.php的输出并将此输出传递给get.html页面并显示输出。这是否可以从html页面访问php输出? 提前谢谢。请帮我解决。
答案 0 :(得分:0)
我不是100%肯定,如果这是你的意思。但是如果你创建一个文件(foo.php)并将它放在output.php
所在的目录中,然后将其添加到foo.php:
<?php
$myfile = fopen("output.php", "r") or die("Unable to open file!");
echo fread($myfile,filesize("output.php"));
fclose($myfile);
?>
然后,应该在浏览器中以HTML格式打印output.php
的内容(如果您在浏览器中转到/foo.php
)。
答案 1 :(得分:0)
在您网站的根目录下创建一个.htaccess
文件。将其放在.htaccess
文件中:
AddType application/x-httpd-php .html .htm
此文件将使Apache解析.html
个文件为PHP。然后在您的get.html
文件中输入以下代码:
<html>
<head></head>
<body><?php include('path/to/output.php'); ?></body>
</html>
如果您在浏览器中查看get.html
文件,则会看到output.php
的输出
将以下代码放入get.html
文件中。这将向您的output.php
文件发出ajax请求,并将响应放在<div id="output"></div>
中。
<html>
<head></head>
<body>
<div id="output"></div>
<script>
var request = new XMLHttpRequest();
request.open('GET', 'output.php', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
document.getElementById('output').innerHTML = request.responseText;
} else {
// We reached our target server, but it returned an error
}
};
request.onerror = function() {
// There was a connection error of some sort
};
request.send();
</script>
</body>
</html>