We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,437 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Problem with fputcsv. Inserting HTML code into csv file

I have problem with writing csv file using fputcsv. Its putting the page html also into the csv file. Whats wrong with my code ?

        //Excel header
        header("Content-Disposition: attachment; filename=\"Delivery_Reports.csv\";" );
        header("Content-type: application/vnd.ms-excel");

        $out = fopen("php://output", 'w');
        $flag = false;
        // $result = mysql_query("SELECT * FROM senderids ") or die('Query failed!'); 
        //$sel="SELECT number as MobileNumber ,snum as Sender , msg as Subject ,crdate as Date ,status FROM  savemsg WHERE userID='".$_SESSION['id']."' ".$str." ORDER BY sn DESC ";
        $result = mysql_query("SELECT `count`, `dnd`, `credit`, `sender_id`, `to`, `message`, `status` FROM `reports` WHERE `unq_id` = '$dlr_id'");
        while(false !== ($row = mysql_fetch_assoc($result))){
            if(!$flag){
                $list = array( "Total"=>"Total","DND"=>"DND","Credits"=>"Credits","From"=>"From","To"=>"To","Message"=>"Message","Status"=>"Status", );
                // display field/column names as first row 
                fputcsv($out, array_keys($list), ',', '"');
                $flag = true; 
            }
            // array_walk($row, 'cleanData');
            fputcsv($out, array_values($row), ',', '"');
        }
        fclose($out);
2
Contributors
1
Reply
11 Hours
Discussion Span
10 Months Ago
Last Updated
2
Views
Question
Answered
rayidi
Junior Poster in Training
83 posts since May 2011
Reputation Points: 13
Solved Threads: 3
Skill Endorsements: 0

You need to give exit; after fclose($out); to avoid further printing of html tags.

ddsuresh
Newbie Poster
11 posts since Nov 2009
Reputation Points: 11
Solved Threads: 4
Skill Endorsements: 0
Question Answered as of 10 Months Ago by ddsuresh

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0589 seconds using 2.73MB