0

I am trying to export the data got from my database.
The problem is that the data comes with html codes.
I just want to export the data without html codes.

Note: My database doesn't have any html code.

$exported_db_datas (global array variable) is created like this:

while($row = mysql_fetch_array($resultset,MYSQL_ASSOC))
{
    $resultsarray[$rowcount] = $row;
    $exported_db_datas[$rowcount] = $row;
    /*foreach($resultsarray[$rowcount] as $column)
    {
        $resultsarray2[$rowcount][] = $column;                  
    }*/

    $rowcount++;        
}

Export codes :

$export_file = "export_phisto";

if ($format == "CSV")
{
    $file = $export_file.".csv";
    $separator = ",";
}
elseif ($format == "TAB")
{
    $file = $export_file.".tab";
    $separator = "\t";
}
elseif ($format == "TXT")
{
    $file = $export_file.".txt";
    $separator = "\t";
}
else// XLS
{
    $file = $export_file.".xls";
    $separator = "\t";
}    


header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Type: text/plain");

$flag = false;
foreach($exported_db_datas as $row)
{
        if(!$flag) 
        {
          // display field/column names as first row
          echo implode($seperator, array_keys($row)) . "\r\n";
          $flag = true;
        }
        echo implode($seperator, array_values($row)) . "\r\n";
}

Note: Even if I don't use print $data, exported data has html codes of the web site without data.

How can I just export the data I get from database?

Example exported data is was here.

CSᵠ
  • 10,049
  • 9
  • 41
  • 64
Viplime
  • 141
  • 4
  • 14
  • possible duplicate of [How to parse and process HTML/XML with PHP?](http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-xml-with-php) – Quentin Jan 12 '13 at 12:25
  • Can you maybe paste a piece of output from `wget` or other stuff that shows what doesn't work as you expect it? – Konrad Neuwirth Jan 12 '13 at 12:26
  • My database includes no html codes.I don't understand why my exported data includes html codes :S – Viplime Jan 12 '13 at 12:30

2 Answers2

5

Use strip_tags

$exported_db_datas[$rowcount] = strip_tags($row);
  • I used it but there are still html codes in exported data.I added this code : echo strip_tags(implode($seperator, array_values($row))); – Viplime Jan 12 '13 at 12:42
0

just use strip_tags() in this line $exported_db_datas[$rowcount] = $row; like so: $exported_db_datas[$rowcount] = strip_tags($row);

PS: don't use the mysql_* extension, it was deprecated, see the red warning box here

CSᵠ
  • 10,049
  • 9
  • 41
  • 64
  • Warning: strip_tags() expects parameter 1 to be string. $row is an array.And problem is not solved :S – Viplime Jan 12 '13 at 12:34
  • @Viplime: you didn't specify that and from your problem description it would seem the data is stored with html. where is your html coming from then? – CSᵠ Jan 12 '13 at 13:08
  • That's the thing i want to learn.Data doesn't contain any html tags.When i echo or print in export mode datas gets html codes. – Viplime Jan 12 '13 at 13:22