Skip to content

Instantly share code, notes, and snippets.

@WenLiangTseng
WenLiangTseng / test_jquery_working_or_not.js
Created July 22, 2013 05:16
測試 jQuery 是否有啟動
<script type="text/javascript">
if (typeof jQuery != 'undefined') {
alert('jQuery working!');
} else {
alert('no jQuery, too bad...');
}
</script>
@WenLiangTseng
WenLiangTseng / input_numbers_only.js
Created July 22, 2013 05:17
讓HTML的輸入框,只能輸入數字
<input type="text" class="numbersOnly" value="" />
//And:
jQuery('.numbersOnly').keyup(function () {
this.value = this.value.replace(/[^0-9\.]/g,'');
});
@WenLiangTseng
WenLiangTseng / click_to_jump_to_specific_tab_page.js
Created July 22, 2013 05:19
讓<a>點到Tab標籤的特定標籤頁
//內部(同一頁)
onclick='$("#tabs").tabs( "select", "tabs-2" )'
//外部(不同頁)
http://www.cglandmark.net/demosite/?page_id=88#thethe-tabs-1-2
//在網址的最後面,加上Tab的ID,例如#thethe-tabs-1-2
@WenLiangTseng
WenLiangTseng / php_mail_function.php
Created July 22, 2013 05:20
PHP寄送郵件的寫法
<?php
/*使用PHP mail()寄送UTF-8編碼之電子郵件
常遇到的問題是,「郵件標題」或「寄件者」是亂碼的問題
主要的原因在於,電子郵件標準格式中,
表頭的部分不允許使用雙位元的文字,
所以,使用mb_encode_mimeheader()函式
將雙位元文字編碼為單位元字串。
*/
@WenLiangTseng
WenLiangTseng / codeigniter_mysql_date_judgement.php
Created July 22, 2013 05:34
CodeIgniter 使用日期判斷的 MySQL 語法
<?php
// if you still want to use AR,
// you could pass a FALSE as third parameter of
// $this->db->where
// to avoid automatic escaping by CI:
$this->db->select('id,name')
->where('dr','1')
->where('end >=', 'CURDATE()', FALSE);
$query = $this->db->get('store');
@WenLiangTseng
WenLiangTseng / codeigniter_call_this_in_function.php
Created July 22, 2013 05:35
CodeIgniter-在函數裡呼叫$this的方法
<?php
function is_logged_in() {
// Get current CodeIgniter instance
$CI =& get_instance();
// We need to use $CI->session instead of $this->session
$user = $CI->session->userdata('user_data');
if (!isset($user)) { return false; } else { return true; }
}
@WenLiangTseng
WenLiangTseng / codeigniter_upload_image_and_text_controller.php
Created July 22, 2013 05:39
CodeIgniter中,同時上傳圖片與文字
<?php
// controller
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
@WenLiangTseng
WenLiangTseng / codeigniter_back_to_previous_page_function.php
Created July 22, 2013 05:41
在CodeIgniter中,建立回到前一頁的功能
<?php
//
function __construct()
{
parent::__construct();
[...]
if (isset($_SERVER['HTTP_REFERER']))
@WenLiangTseng
WenLiangTseng / curl_example.php
Created July 22, 2013 05:41
使用CURL抓資料的PHP函數,可以給予URL資料,然後得到回傳的結果
<?php
$xml_file = file_get_contents(SITE_PATH . 'cms/data.php');
//CURL
function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
@WenLiangTseng
WenLiangTseng / php_use_html_mail_template.php
Created July 22, 2013 05:46
PHP使用HTML郵件版型
<?php
/*You could put a PHP script inside the template
and then have PHP itself do the rendering,
for example:
*/
//template.html:
?>
<div clas="headr"></div>