GD extension 因為 gif 授權上的關係,不再支援 gif 的格式,如果想要用 gif 檔,請找較舊的 GD extension 試試。下列為較有彈性的做法:
if (function_exists("imagegif")) {
header("Content-type: image/gif");
imagegif($im);
} elseif (function_exists("imagejpeg")) {
header("Content-type: image/jpeg");
imagejpeg($im, "", 0.5);
} elseif (function_exists("imagepng")) {
header("Content-type: image/png");
imagepng($im);
} elseif (function_exists("imagewbmp")) {
header("Content-type: image/vnd.wap.wbmp");
imagewbmp($im);
} else {
die("No image support in this PHP server");
}
在新舊版本的 PHP 中,有可能影響到老版本的程式碼的最重要的兩點改動分別是:
因為全域變數的取消,在表單資料的取得上也需要有新的修正,必需依據表單 submit 方法的不同,分別利用 $_POST[‘變數名’] 和 $_GET[‘變數名’] 來取得變數的資料,例子如下:
<form action="action.php" method="POST">
Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
<input type="submit"></form>
PHP 程式如下
Hi < ?php echo $_POST["name"]; ? > . You are < ?php echo $_POST["age"]; ? > years old.
該程式的輸出可能是:
Hi Joe. You are 22 years old.
列出較常用的轉義字元
| 含義 | |
| \n | 換行(LF 或 ASCII 字元 0x0A(10)) |
| \r | 回車(CR 或 ASCII 字元 0x0D(13)) |
| \t | 水平制表符(HT 或 ASCII 字元 0x09(9)) |
| \\ | 反斜線 |
| \$ | 美元符號 |
| \" | 雙引號 |
| \[0-7]{1,3} | 此正則表達式序列匹配一個用八進制符號表示的字元 |
| \x[0-9A-Fa-f]{1,2} | 此正則表達式序列匹配一個用十六進制符號表示的字元 |
关于Unicode 04/05/31 03:12 这两天总是提及到Unicode,Utf-8,先是 TT 不支持 UTF-8 ,使 TrackBack 如同鸡肋,
然后就是鱼要我做的一个直接显示文字在图片上的小程序,都要使用到 Unicode,于是想到去年做 WAP 时用到的程序,
当时发布在www.php.net上,
有一点点错误,后来我修改好了放在自己的 WAP 上,现在公开一下代码吧;) <? # Functions Of Wap.LuoYi.Com # Coded by Roy Law roylaw#263.net # 2003-5-21 22:47:22 function gb2unicode($gb) { if(!trim($gb)) return $gb; $filename="gb2312.txt"; $tmp=file($filename); $codetable=array(); while(list($key,$value)=each($tmp)) $codetable[hexdec(substr($value,0,6))]=substr($value,9,4); $utf=""; while($gb) { if (ord(substr($gb,0,1))>127) { $this=substr($gb,0,2); $gb=substr($gb,2,strlen($gb)); $utf.="&#x".$codetable[hexdec(bin2hex($this))-0x8080].";"; } else { $utf.=substr($gb,0,1); $gb=substr($gb,1,strlen($gb)); } } return $utf; } ?>
这个函数需要一个gb2312的码表文件,这里下载
ftp://ftp.unicode.org/Public/MAPPINGS/EASTASIA/GB/GB2312.TXT
请注意文件名大小写的问题。
GB2312.zip (42.8 KB)
这里提供一个简化的 GB2312.TXT 文件。