PHP中字體應用釋疑
來源:程序員人生 發布時間:2014-01-02 20:59:30 閱讀次數:3837次
綜述:有許多朋友對網站提供繁、簡兩種版本感到很困惑,是怎么實現的呢?這也是時下眾多PHP書籍中被漏掉的一個很重要的知識點。筆者搜集整理并根據自己的開發經驗將一些重點與疑點羅列出來與大家共享!
如何應用繁體中文轉換為簡體中文的PHP函數:
- <?
-
-
- function big5togb($code)
- {
-
- include "data_big5.php";
- $output="";
- $length=strlen($code);
- $code=strtok($code,"");
- $idx=0;
- while ($idx < $length)
- {
- $tmpStr=$code[$idx].$code[$idx 1];
-
- if (isbig5($tmpStr))
- {
- ……
- }
- else
- {
- $output.= $code[$idx];
- }
- $idx ;
- }
- return ($output);
- }
- ?>
如何應用簡體中文轉換為繁體中文的PHP函數?我們定義一個big5togb的函數來實現這個轉換:
- function gbtobig5($code)
- {
- include "data_gb.php";
- $output="";
- $length=strlen($code);
- $code=strtok($code,"");
- $idx=0;
- while ($idx < $length)
- {
- $tmpStr=$code[$idx].$code[$idx 1];
-
- if (isgb($tmpStr))
- {
- ……
- }
- else
- {
- $output.= $code[$idx];
- }
- $idx ;
- }
- return ($output);
- }
在簡繁體轉換中怎樣應用PHP輸出控制功能?PHP輸出控制功能是怎樣一回事?
PHP的輸出信息控制函數可以讓你控制你的腳本輸出的內容,可以用于許多不同的情況,非凡是在你的腳本已經輸出信息后需要發送文件頭的情況以及需要對輸出信息進行編輯處理的地方。輸出控制函數不對使用header()或setcookie()發送的文件頭信息產生影響,只對那些類似于echo()、print() 和 PHP 代碼的數據塊有作用,
例題控制輸出:test.php
- <?
- function test($str){
- return str_replace("world","php",$str);
- }
- ob_start("test");
- echo "hello world";
- ob_end_flush();
- ?>
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈