Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MYSQL/PHP中从html代码中剥离数据_Php_Sql_Phpexcel - Fatal编程技术网

如何在MYSQL/PHP中从html代码中剥离数据

如何在MYSQL/PHP中从html代码中剥离数据,php,sql,phpexcel,Php,Sql,Phpexcel,我在MYSQL中有一个表,看起来像这样(注意html代码): ===================================================================| | Question | Answer | =========+===========+=============================================| | <p>

我在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中的代码:

$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++;}
}
使用


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

这个问题与相同吗?不,这个问题是如何删除带有html的行。这只是剥离html并保留数据。你是对的。我没想到会这么容易。谢谢
$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++;}
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, strip_tags($value));