export multiline field to .csv
-
if u have multiline field cells u want to export to .csv
/* Export table to .csv file */ if (isset($_GET['action']) && $_GET['action'] == 'export_table_content') { $nonce = $_GET['_wpnonce']; if ( empty($_GET) || !wp_verify_nonce($nonce, 'export-table-content' ) ) { print 'Sorry, you cannot process data this way.'; exit; } else { $output = ''; $exportArray = array(); $id = $_GET['export_id']; $name = $_GET['exports_name']; global $wpdb; $table_name = $wpdb->prefix . "websimon_tables"; $results = $wpdb->get_results("SELECT headlines, content FROM $table_name WHERE id='$id'"); foreach ($results as $result) { //add headlines $headArray = explode('[-|-]', $result->headlines); $count = 0; foreach ($headArray as $elem) { if ($count == 0) { $cell = str_replace(array('\r\n','\r','\n'), '\n', $cell); $output .= '"'. utf8_decode($elem).'"'; } else { $cell = str_replace(array('\r\n','\r','\n'), '\n', $cell); $output .= ';"' . utf8_decode($elem).'"'; } $count++; } $output .= "\r\n"; //add content $bodyArray = explode('[-%row%-]' , $result->content); foreach ($bodyArray as $elem) { $count = 0; $rowArray = explode('[-%cell%-]', $elem); foreach ($rowArray as $cell) { if ($count == 0) { $cell = str_replace(array('\r\n','\r','\n'), '\n', $cell); $output .= '"'. utf8_decode($cell).'"'; } else { $cell = str_replace(array('\r\n','\r','\n'), '\n', $cell); $output .= ';"' . utf8_decode($cell).'"'; } $count++; } $output .= "\r\n"; } } $sitename = get_bloginfo( 'url' ); $filename = 'exports-table-' . $name . '.csv'; header( 'Content-Description: File Transfer' ); header( 'Content-Disposition: attachment; filename=' . $filename ); header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ), true ); echo $output; exit; } }
The topic ‘export multiline field to .csv’ is closed to new replies.