PHP
Page Redirection
Dec 16th
เมื่อวันก่อนมีน้องมาถามเกี่ยวกับเรื่อง Page Redirection ก็เลยคิดว่าจะเอามาเป็นพูดถึงเสียหน่อย
การ redirect หน้าเว็บ คือการส่งหน้าเว็บที่เปิดอยู่ปัจจุบันไปยังหน้าอื่น สามารถทำได้ 3 ระดับดังนี้
- ระดับ HTTP Header
- ระดับ HTML Header
- ระดับ Script
I’m noob
Mar 6th
It’s closely to 10 years that i coding web application in PHP. The advantage of its is the text management, easy to read and write code, and power of hash array.
I usually use array in many program or library to store data. And have one case that I never know about it, The “Array node removing”. I usually loop the array and move keep node into new array. Yes! it’s too waste.. but I don’t know how can i do for remove node. It have array_pop() and array_shift() but cannot remove specific node.
Today I found the way to do that!!! it just use unset()!!! it never bring up in my brain. Actually unexpected … and it work !!!!
PHP lite-weight themes
Nov 8th
Hello! It’s too long time that I didnt update this blog. Today I have new custom lib for php programmer. It’s lite-weight themes system (for anyone who dont want to use smarty). It may not as good as smarty can do but it’s easy for designer, They didnt know any structure. just mark where is for content with “${}”.
<?php
/*write by. mrKrich (Bhanu Thangpulphol)email: mrkrich@msn.com*/
class themes{
private $filename = "";private $rawdata = "";private $cache = "";private $cachemd5 = "";private $mapping = Array();
public function __construct($filename){ $this->setTemplate($filename);}
public function setTemplate($filename){ $this->filename = $filename; $this->rawdata = join("", file($filename)); $this->cachemd5 = md5($this->rawdata); preg_match_all("/\\$\{([^\}]+)\}/Ui", $this->rawdata, $res); foreach($res[1] as $r){ $this->mapping[$r] = ""; }}
public function setMap($key, $value){ $this->mapping[$key] = $value;}
public function clearMap(){ $this->mapping = Array();}
public function clearCache(){ $this->cache = ""; $this->cachemd5 = "";}
private function map(){ $res = $this->rawdata; foreach($this->mapping as $i=>$d){ $res = str_replace("\${" . $i . "}", $d, $res); } return $res;}
private function checkversion(){ $md5 = md5($this->rawdata . print_r($this->mapping, true)); return ($this->cachemd5 == $md5);}
private function merge(){ if(!$this->checkversion() && $this->cache==""){ $res = $this->map(); $this->cache = $res; $this->cachemd5 = md5($this->rawdata . print_r($this->mapping, true)); } return $this->cache;}
public function __toString(){ return $this->merge();}
}
?>
you also can download , modify or use anywhere but please reference to me (for the based code) and you (for your changed code).
the overlook function
Feb 10th
I used to talk about font encoding, I used header() to solve it. Today I found another function to convert the encoding, It’s iconv().
When I finding for encoding converter. I proof reading all and pass the unknown and unrelated topic. iconv is one of it. Because I think it be the function about “icon” … yes icon, an images link/reference to any program or function.
Iconv is the standard programming interface for converting character strings from one character encoding to another in Unix-like operating systems.
In php it’s so easy to use like this
$utf8_string = iconv(“TIS-620″, “UTF-8″, $tis620_string);
Is it easy?
HTTP Header
Feb 2nd
on my testing web. I try to use AJAX on my site and found some error if i use non unicode. may be my page encoding or somethings wrong behind the protocol.
so i try to use UTF-8 for this problem. So i found another problem to solve!!!
i put this line on my HTML
<meta http-equiv=Content-Type content="text/html; charset=UTF-8"/>
it found, but not set my page to UTF-8 as set!! (You can check with page info in firefox)
after search in too many site i found something.
My web server was set default charset/encoding to ISO8859-11 / TIS-620 / WIndows-874/ CP874 (Thai)
so i have only two choice to do. Change web server setting or customize http header
I’ll not talk to change default web server configuration for charset/encoding so i will talk about how to customize http header
php: use command header() to set content-type like this
header(“Content-Type: text/html; charset=UTF-8;”);
jsp: you usually use this in your code
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
so on another programming language must have its own way to do something like this
