PHP chained operation outputs excel (csv) and chained csv. PHP chain operation outputs excel (csv). in the chain csv work, we often encounter product operations that allow you to export some simple and standardized data, at this time, if there is a simple way to output excel (csv) and chain csv via PHP chain operation
In our work, we often encounter product operations that allow you to export some simple and standardized data. at this time, it would be much easier to use a simple method. The following is a simple excel (csv) Method class that I use for chained operations. When it comes to chained operations, which may be frequently used in jquery, do you also feel that chained operations are quite helpful? we also implement chained operations in this class.
In fact, the chain operation is very simple, that is, the previous class method returns an object of this class ($ this), provided to the next method call.
Ext = $ ext = null? $ This-> ext: $ ext; header ("Content-Disposition: attachment; filename = ". $ filename. ". ". $ this-> ext); ob_flush (); return $ this ;} /*** @ desc print the excel title * @ param array $ title the line of the title to be output * @ param object Array2csv object itself */public function title ($ title) {$ title = implode (",", $ title); echo $ title. "\ n"; return $ this;}/*** @ desc print a row of excel content * @ param array $ body content to be output * @ param object Array2csv object itself */public Function body ($ body) {if (! Is_array ($ body) | empty ($ body) {return false;} $ body = implode (",", $ body); echo $ body. "\ n"; return $ this ;} /*** @ desc print multi-row excel content * @ param array $ bodyArr multi-row content to be output * @ param object Array2csv object itself */public function multiBody ($ bodyArr) {if (! Is_array ($ bodyArr) | empty ($ bodyArr) return false; foreach ($ bodyArr as $ key => $ value) {if (is_array ($ value )) {$ value = implode (",", $ value); echo $ value. "\ n" ;}}return $ this ;}$ test = new Array2csv ('test'); $ arr = array ('luluyrt @ 163.com ', 'runningman1', 'runninguserman'), array ('luluyrt @ 163.com ', 'runningman2', 'runninguserman '), array ('luluyrt @ 163.com ', 'Running man3', 'Running userman'), array ('luluyrt @ 163.com ', 'Running man4 ', 'runninguserman'), array ('luluyrt @ 163.com ', 'runningman5', 'runninguserman'), array ('luluyrt @ 163.com ', 'runningman6', 'runninguserman'); $ test-> title (array ('test', 'hha ', 'Haha ')) -> body (array ('2017, sadkl ', 'sdsas', 'sdvsvdd sub')-> multiBody ($ arr );
Shows the output csv file:
$ Link = mysqli_connect ($ host, $ user, $ passwd, $ db); mysqli_query ($ link, "set names utf8 ");
Only after encoding conversion can the information be displayed normally. the following shows the information about my database and the effect before and after encoding:
Database information
Comparison before and after Database encoding
Send Me ~
Export (csv), chained csv jobs often encounter product operations that allow you to export some simple and standardized data. at this time, if there is a simple method that can be used...