0

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++;}
}
2
  • Is this question the same as stackoverflow.com/questions/13243332 ? Commented Dec 4, 2012 at 0:53
  • No, that question is how to remove a row with html. This is just about stripping the html and leaving the data. Commented Dec 4, 2012 at 1:00

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

You're right about that. I didn't think it would be so easy. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.