顯示具有 php 標籤的文章。 顯示所有文章
顯示具有 php 標籤的文章。 顯示所有文章

Random CSS Hex Color by PHP

  • 0
$rnd = Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
$rnd_color = "#";
for ($i=0; $i<6; $i++) {
    $rnd_color .= $rnd[rand(0,15)];
}

Reference: Random Hex Color

[AJAX] Echo PHP Array by JSON

  • 0
雖然 jQuery AJAX 中,要 echo string 回去,
但天真地試圖傳 array 回去,會cannot convert an array to a string
所以請使用

[PHP] array length count() vs. sizeof()

基本上是一樣的,但 count() 可能在多人維護上比較好、較易懂 (? 見人建智)
Reference: stackoverflow,  Andreas Glaser

[php] date() 更改時間格式

  • 0
date()
string date ( string $format [, int $timestamp = time() ] )
可以將輸入的 time 自由更改格式
Reference: PHP date函數參數詳解

[php] split string by explode()

$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

explode()

php 字串搜尋取代 str_replace()

  • 0
str_replace($search, $replace, $subject)

// Output $newphrase: You should eat pizza, beer, and ice cream every day
$phrase  "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits""vegetables""fiber");
$yummy   = array("pizza""beer""ice cream");

$newphrase str_replace($healthy$yummy$phrase);

reference: str_replace()

php urldecode() vs. rawurldecode()

Same: Decode URL-encoded strings
Difference: rawurldecode() does not decode plus symbols ('+') into spaces. urldecode() does.

Reference: rawurldecode(), urlencode()

(轉) 加強PHP安全性的幾個原則

  • 1

加強PHP安全性的幾個原則

作為PHP程式師,特別是新手,對於互聯網的險惡總是知道的太少,對於外部的入侵有很多時候是素手無策的,他們根本不知道駭客是如何入侵的、提交入侵、上傳漏洞、sql 注入、跨腳本攻擊等等。作為最基本的防範你需要注意你的外部提交,做好第一面安全機制處理防火牆。

[php] CodeIgniter MVC

  • 0

● Models
Model檔案名稱
     Model_name是類別名稱。類別名稱必須第一個字母大寫其餘的字母小寫
     檔案名稱是全部小寫的類別名稱
Model 只在 Controller 的函數中才會被載入/呼叫
Active Record 類別
class Blog_controller extends CI_Controller {
    function blog() {
        $this->load->model('Blog');

        $data['query'] = $this->Blog->get_last_ten_entries();

        $this->load->view('blog',$data);
    }

[php] CodeIgniter views

  • 0
Views
Views無法直接被呼叫,它必須被Controller所呼叫。可一次載入多個views
收納子目錄: $this->load->view('folder_name/file_name'); // view資料夾裡的位置
新增動態資料到 View
可由 array 或是 object 的方式傳遞

php codeigniter url rewrite localhost

  • 0

Appserv\www\proj_name\.htaccess
RewriteEngine On
RewriteCond $1 !^(index\.php|bbs|activity|img|image|css|blog|js|store|deco_designer|blog|back_private_admin|designer|upload_request_image|wiki|robots\.txt|favoicon.ico)
RewriteRule ^(.*)$ index.php/$1 [L] 


Apache\conf\httpd.conf
AllowOverride NONE -> AllowOverride All
#LoadModule rewrite_module modules/mod_rewrite.so -> LoadModule rewrite_module modules/mod_rewrite.so
Appserv\www\proj_name\application\config\config.php
$config['base_url']        = 'http://localhost/proj_name';
$config['index_page'] = '';

localhost php.ini

應該要修改 C:\Windows\php.ini 才會對 localhost 的有影響

appserv windows 7 setup

使用 appserv-win32-2.6.0phpMyAdmin-3.5.6-all-languages

用 php 判斷使用者語言 browser language

  • 0

<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
   case "zh": include("_home_zh.php"); break;
   default:   include("_home_en.php"); break;
}
?>