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