Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将包含php头格式/函数的php代码包含到HTML分区中_Php_Html_Web - Fatal编程技术网

如何将包含php头格式/函数的php代码包含到HTML分区中

如何将包含php头格式/函数的php代码包含到HTML分区中,php,html,web,Php,Html,Web,下面是sample.php <?php $con=mysql_connect("localhost","root",""); mysql_select_db("final_year_sample",$con); $qt=mysql_query("select * from gd_graph"); header("Content-Type:image/jpg"); $x_gap=40; $x_max=$x_gap*13; $y_max=

下面是sample.php

<?php
    $con=mysql_connect("localhost","root","");
    mysql_select_db("final_year_sample",$con);
    $qt=mysql_query("select * from gd_graph");
    header("Content-Type:image/jpg");
    $x_gap=40;
    $x_max=$x_gap*13;
    $y_max=250;
    $im = ImageCreate($x_max, $y_max) or die ("Cannot Initialize new GD image stream");
    $background_color = ImageColorAllocate($im, 234, 234, 234);
    $text_color = ImageColorAllocate($im, 233, 14, 91);
    $graph_color = ImageColorAllocate($im,25,25,250);
    $x1=0;
    $y1=0;
    $first_one="yes";
    while($nt = mysql_fetch_array($qt)){
        $x2=$x1+$x_gap;
        $y2=$y_max-$nt['sales'];

        ImageString($im,2,$x2,$y2,$nt['month'],$graph_color); 
        if($first_one=="no"){
            imageline($im,$x1, $y1,$x2,$y2,$text_color);
        }
        $x1=$x2;
        $y1=$y2;
        $first_one="no";
    }
    ImageJPEG($im);
?>

上面的sample.php代码运行良好,输出如下

我想做的是:

我想在下面的HTML页面中包含sample.php

    <html>
    <head>
        <title>Front page</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div id="container">
            <span id="title">Prototype for vehicle Routing problem Solution</span>
            <div style="display:none;" id="graph_space">
                <?php
                    include('sample.php');
                ?>
            </div>
        </div>
    </body>
</html>

头版
车辆路径问题求解原型
但我得到了以下错误


您不能在html文件中包含PHP文件,因为html文件无法识别
标记

尽管你可以试着这么做 在目录中创建一个.htaccess文件,并将此代码添加到.htaccess文件中

AddHandler x-httpd-php .html .htm


它将强制Apache服务器将HTML或HTM文件解析为PHP脚本

您必须将文件声明为带有“HTML在内”的
.PHP
页面。更改:
page.html>page.php

然后您的include将运行,它不能在静态HTML页面上运行。想想看,哟。

可能是重复的
AddType application/x-httpd-php .html .htm