doubaben7394 2015-09-14 12:25
浏览 18
已采纳

删除/忽略csv文件中的html标记

been having this problem for a while now, I found many topics about this problem, but they don't really help me.

So Im creating 2 .csv files with this code :

<?php 
include 'cnn.php';
$result = mysql_query("SELECT * FROM www_jrpic_lv.web_notikumi_laiki");

//web_notikumi_laiki un web_notikumi izvade

$data = fopen('web_notikumi.csv', 'w');
$data2= fopen('web_notikumi_laiki.csv','w');

//Output Column Headings
fputcsv($data,array('ID Laiks','ID Notikums','Notikuma Laiks','Notikuma beigu laiks'));
fputcsv($data2,array('ID_not','Notikuma apraksts','Notikuma atbildīgais','Notikuma atskats','Baneris','Klase','Nosaukums','Piederība','piev.laiks','red.laiks','ID Tips','Titulbilde','Vieta'));

//Retrieve the data from database
$rows = mysql_query('SELECT * FROM web_notikumi_laiki');
$rows2 = mysql_query('SELECT * FROM web_notikumi');

//Loop through the data to store them inside CSV

while($row = mysql_fetch_assoc($rows)){
    fputcsv($data, $row);
    }
while($row2=mysql_fetch_assoc($rows2)){
    fputcsv($data2,$row2);
}
echo '<p>web_notikumi dati ir ievadīti';
echo '<p>web_notikumi_laiki dati ir ievadīti';
fclose($data);
fclose($data2);
exit();
?>

Data from table web_notikumi_laiki works well for me, but data in table web_notikumi contains lots of <p> tags . And after I use web_notikumi.csv file to fill table in other server it creates new entry after every <p> tag so i get ~12 000 entries instead of ~2000. My question : Can I remove those tags before I write it to .csv file? If not what options I have.

  • 写回答

1条回答 默认 最新

  • douhaoqiao9304 2015-09-14 13:21
    关注

    You can use strip_tags() to remove any HTML tags from a string. If some HTML elements are allowed, you can whitelist those in the second argument.

    // for a single column from the query result
    fputcsv( $data, strip_tags( $row['column_name'] ) );
    
    // for all columns in the query result
    fputcsv( $data, array_map( 'strip_tags', $row ) );
    

    See: http://php.net/strip_tags

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?