Merica
Merica

Reputation: 129

How to strip data out of html code in MYSQL/PHP

I have a table in MYSQL that looks like this (notice the html code):

===================================================================|
|           Question                         |   Answer            |
=========+===========+=============================================|
| <p> Do you listen to music? </p>           |        YES          |            
|------------------------------------------------------------------|
| Who is your favorite music artists?        | Justin Beiber       | 
|------------------------------------------------------------------|
|<script>Are you a Male or female?</script>  |      M              | 
|------------------------------------------------------------------|

I am using PHPExcel in PHP to extract that data and place it in an excel file, and that table is what my excel file looks like.

In excel I want the html removed so that the fields only contain the question:

===================================================================|
|           Question                         |   Answer            |
=========+===========+=============================================|
|     Do you listen to music?                |        YES          |            
|------------------------------------------------------------------|
| Who is your favorite music artists?        | Justin Beiber       | 
|------------------------------------------------------------------|
|      Are you a Male or female?             |      M              | 
|------------------------------------------------------------------|

The code in PHP:

$col=1; // 1-based index
while($row_data = mysql_fetch_assoc($result)) {

$row= 1;

    foreach ($row_data as $key=>$value) {

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$row++;
    }
    $col++;

}

$row=1;
while($row_data = mysql_fetch_assoc($result2)) {
$col=0;

    foreach($row_data as $value) {

   $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
        $row++;

    $col++;}
}

Upvotes: 0

Views: 586

Answers (1)

John Conde
John Conde

Reputation: 219894

Use strip_tags()

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, strip_tags($value));

This is a good example of why HTM should not be mixed with content in a database

Upvotes: 2

Related Questions