0

我在 MYSQL 中有一个如下所示的表(注意 html 代码)

===================================================================|
|           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              | 
|------------------------------------------------------------------|

我在 PHP 中使用 PHPExcel 来提取该数据并将其放入一个 excel 文件中,该表就是我的 excel 文件的样子。

在 excel 中,我希望删除 html,以便字段仅包含问题:

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

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++;}
}
4

1 回答 1

2

采用strip_tags()

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

这是一个很好的例子,说明为什么 HTM 不应该与数据库中的内容混合

于 2012-12-04T00:51:53.233 回答