我的PHP代码出现在导出的CSV文档中

Sta*_*umo 0 php mysql csv

我现在已经开始将文档导出为CSV格式.但我遇到了问题.

一旦我将CSV标头引入代码,任何后续PHP都会出现在导出的CSV文档中,而不是我想要的信息.

请帮助我.

header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=".$_GET['docname'].".csv");

//the php for getting the info
mysql_connect("localhost","root", "");
mysql_select_db("mydb");    

//CSV Processing
    $sql_csv = mysql_query($query); 
    $tCount = mysql_num_fields($sql_csv);

    //the first line is for the column names
    for($i=0; $i<=($tCount-1); $i++)
    {
        if(mysql_field_name($tColumns,$i)!='')
        {
            echo ucfirst(mysql_field_name($tColumns,$i)).',\n'; 
        }
    }

    while($row = mysql_fetch_row($sql_csv)) 
    {
        echo '"' . stripslashes(implode('","',$row)) . "\"\n";
    }

    exit;
Run Code Online (Sandbox Code Playgroud)

GWW*_*GWW 7

在我看来,你错过了开场<?php标签.