Skip to content

Instantly share code, notes, and snippets.

View EricYue2012's full-sized avatar

Eric Yue EricYue2012

  • Sydney
View GitHub Profile
@EricYue2012
EricYue2012 / php_output_excel
Created December 6, 2013 00:40
PHP output excel file
http://stackoverflow.com/questions/8082523/export-records-in-excel-file
1. Do query in php to get the rows you want to output
2. You can use SELECT * FROM table WHERE id IN (1,2,...)
3. Use mysql_fetch_array() or mysql_fetch_assoc() to get the rows one at a time
4. Use fputcsv() to output them to a file ending in csv - this will properly escape your data
Excel will be able to read the file.
Override the defaults for fputcsv to use tabs for delimiters and Excel will have an even easier time reading the file. If you use commas (the default) you may need to pick commas as the delimiter on Excel import.
@EricYue2012
EricYue2012 / functions.php
Last active August 6, 2021 01:47
WordPress
<?php
// 1. 显示当前模板文件的路径
// 1. show template file for page
// - put in theme functions.php
function ey_which_template_is_loaded() {
if ( is_super_admin() ) {
global $template;
print_r( $template );
}
@EricYue2012
EricYue2012 / lib.js
Last active August 6, 2021 01:49
javascript
// 1. 按名字取得网址中的query string
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// example
// current URL: http: //www.test.com/index.php?name=John