这个不是主要问题的:if(($strArray[i]=="p_statue") ¦ ¦($strArray[i]=="p_firstname") ¦ ¦($strArray[i]=="p_lastname")) 

解决方案 »

  1.   

     header('Content-type: text/plain');
      header('Content-Disposition: attachment; filename="'.$_GET['list'].'_'.$_GET['startyear'].str_pad($_GET['startmonth'],2,'0').str_pad($_GET['startday'],2,'0').'-'.$_GET['endyear'].str_pad($_GET['endmonth'],2,'0').str_pad($_GET['endday'],2,'0').'_'.$reporttype.'.csv"');
      echo "\"EmailAddr\",\"List\",\"Timestamp\",\"LG_status\",\"LG_message\",\"Anrede\",\"Vorname\",\" Nachname\",\"Strasse\",\"Hausnummer\",\"PLZ\",\"Ort\"\r\n";  while ($row = mssql_fetch_array($EXEC)) {
        $i=0;
        while($strArray=split('[&=]',$row['profiles']))
    {
    if(($strArray[i]=="P_Title")||($strArray[i]=="P_FirstName")||($strArray[i]=="P_LastName")||($strArray=="P_Strasse")||($strArray=="P_Hausnummer")||($strArray=="P_PLZ")||($strArray[i]=="P_Ort")){
       $i++;
       array_push($strArray[i]);
       }    
    }
        echo "\"".$row['EmailAddr']."\",\"".$row['List']."\",\"".$row['RequestTime']."\",\"".$row['LG_status']."\",\"".$row['LG_message']."\",\"".$strarray[0]."\",\"".$strarray[1]."\",\"".$strarray[2]."\",\"".$strarray[3]."\",\"".$strarray[4]."\",\"".$strarray[5]."\",\"".$strarray[6]."\"\r\n";
      }
    这是比较完整的代码,是将数据库中的数据取出来放到excel文件中。其中由一个profiles字段很长,格式类似我在上面写的那样。但是运行后,下载的excel文件非常之大(貌似有点死循环),实际上这个文件只有2kb。不知道是什么原因?
    请高手解答一下,谢谢
      

  2.   

    先把header去了调试下,
    在生成最终的字符串之前,把要生成的excel的列数输出一下,看问题出在哪里
      

  3.   

    出的是这个错误:Use of undefined constant i
      

  4.   

    还有这个Undefined index: i 
      

  5.   

    如果你需要的是p_statue,p_firstname,p_lastname,使用正则提取一下就好了$str="p_statue=sds&p_client=fd&p_firstname=hellot&p_fd=adfjkd&p_lastname=df";
    preg_match_all('/(p_statue|p_firstname|p_lastname)=([^&]+)/i',$str,$m);
    if($m)//匹配
    {
      echo "p_statue=".$m[2][0]."\n";
      echo "p_firstname=".$m[2][1]."\n";
      echo "p_lastname=".$m[2][2]."\n";
    }
    //$m[2]是你需要的值,出现先后和你的模式的第一个匹配项出现先后一致
      

  6.   

    $array = array();
    $strArray = split("[&=]",$str);
    $count = count($strArray);
    for($i=0;$i<$count;$i++){
    if(($strArray[$i]=="p_statue")||($strArray[$i]=="p_firstname")||($strArray[$i]=="p_lastname")) 

      array_push($array,$strArray[$i]); 


    }
    echo "<br>";
    print_r($array);