1、如果你用过smarty模板引擎、MVC类似框架如tp,那么你自己写一个框架噢!
2、你要对php的继承实现以及其中的小知识点熟知;
3、先列出你的框架目录,什么地方放什么,然后写你的配置文件
4、用到的高频函数有:require 、 require_once 、 file_exites等!
如:sybase_connect连上数据库。
语法: int sybase_connect(string [servername], string [username], string [password]);
返回值: 整数函数种类: 数据库功能 本函数用来打开与 Sybase 数据库的连接。
参数 servername 为欲连上的数据库服务器名称。
参数 username 及 password 可省略,分别为连接使用的帐号及密码。
使用本函数需注意早点关闭数据库,以减少系统的负担。
连接成功则返回数据库的连接代号,失败返回 false 值。
?php
function getfirstchar($s0){
$fchar = ord($s0{0});
if($fchar = ord("A") and $fchar = ord("z") )return strtoupper($s0{0});
$s1 = iconv("UTF-8","gb2312", $s0);
$s2 = iconv("gb2312","UTF-8", $s1);
if($s2 == $s0){$s = $s1;}else{$s = $s0;}
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if($asc = -20319 and $asc = -20284) return "A";
if($asc = -20283 and $asc = -19776) return "B";
if($asc = -19775 and $asc = -19219) return "C";
if($asc = -19218 and $asc = -18711) return "D";
if($asc = -18710 and $asc = -18527) return "E";
if($asc = -18526 and $asc = -18240) return "F";
if($asc = -18239 and $asc = -17923) return "G";
if($asc = -17922 and $asc = -17418) return "H";
if($asc = -17417 and $asc = -16475) return "J";
if($asc = -16474 and $asc = -16213) return "K";
if($asc = -16212 and $asc = -15641) return "L";
if($asc = -15640 and $asc = -15166) return "M";
if($asc = -15165 and $asc = -14923) return "N";
if($asc = -14922 and $asc = -14915) return "O";
if($asc = -14914 and $asc = -14631) return "P";
if($asc = -14630 and $asc = -14150) return "Q";
if($asc = -14149 and $asc = -14091) return "R";
if($asc = -14090 and $asc = -13319) return "S";
if($asc = -13318 and $asc = -12839) return "T";
if($asc = -12838 and $asc = -12557) return "W";
if($asc = -12556 and $asc = -11848) return "X";
if($asc = -11847 and $asc = -11056) return "Y";
if($asc = -11055 and $asc = -10247) return "Z";
return null;
}
function make_semiangle($str){
$arr = array('0' = '0', '1' = '1', '2' = '2', '3' = '3', '4' = '4', '5' = '5', '6' = '6', '7' = '7', '8' = '8', '9' = '9', 'A' = 'A', 'B' = 'B', 'C' = 'C', 'D' = 'D', 'E' = 'E', 'F' = 'F', 'G' = 'G', 'H' = 'H', 'I' = 'I', 'J' = 'J', 'K' = 'K', 'L' = 'L', 'M' = 'M', 'N' = 'N', 'O' = 'O', 'P' = 'P', 'Q' = 'Q', 'R' = 'R', 'S' = 'S', 'T' = 'T', 'U' = 'U', 'V' = 'V', 'W' = 'W', 'X' = 'X', 'Y' = 'Y', 'Z' = 'Z', 'a' = 'a', 'b' = 'b', 'c' = 'c', 'd' = 'd', 'e' = 'e', 'f' = 'f', 'g' = 'g', 'h' = 'h', 'i' = 'i', 'j' = 'j', 'k' = 'k', 'l' = 'l', 'm' = 'm', 'n' = 'n', 'o' = 'o', 'p' = 'p', 'q' = 'q', 'r' = 'r', 's' = 's', 't' = 't', 'u' = 'u', 'v' = 'v', 'w' = 'w', 'x' = 'x', 'y' = 'y', 'z' = 'z', '(' = '(', ')' = ')', '〔' = '[', '〕' = ']', '【' = '[', '】' = ']', '〖' = '[', '〗' = ']', '“' = '"', '”' = '"', '‘' = '\'', '’' = '\'', '{' = '{', '}' = '}', '《' = '', '》' = '', '%' = '%', '+' = '+', '—' = '-', '-' = '-', '~' = '-', ':' = ':', '。' = '.', '、' = ',', ',' = ',', ';' = ';', '?' = '?', '!' = '!', '…' = '...', '‖' = '|', '|' = '|', '〃' = '"', ' ' = ' ');
return strtr($str, $arr);
}
function pinyin1($zh){
$zh = make_semiangle($zh);
$ret = "";
$s1 = iconv("UTF-8","gb2312", $zh);
$s2 = iconv("gb2312","UTF-8", $s1);
if($s2 == $zh){$zh = $s1;}
for($i = 0; $i strlen($zh); $i++){
$s1 = substr($zh,$i,1);
$p = ord($s1);
if($p 160){
$s2 = substr($zh,$i++,2);
$ret .= getfirstchar($s2);
}else{
$ret .= $s1;
}
}
return $ret;
}
//用法
echo pinyin1('中文获取首字母大写,‘支持’全角“的”转化!');
?
数字跟英文的全角被百度自动转了,如果需要下载附件源码
原始代码有些问题,我做了些更改,原地址github 的 chenall/chenall/blob/master/php/tools/ZH-cn_TO_pinyin.php
?php
/*
中文汉字转拼音首字母的PHP简易实现方法.
要求: 只能是GB2312码表里面中文字符
转换得到字符串对应的拼音首字母大写.
用法:
echo zh2py::conv('Chinese 中华人民共和国');//Chinese ZHRMGHG
或
$py = new zh2py;
echo $py-conv('Chinese 中华人民共和国');//Chinese ZHRMGHG
*/
class zh2py
{
//根据汉字区位表
//我们可以看到从16-55区之间是按拼音字母排序的,所以我们只需要判断某个汉字的区位码就可以得知它的拼音首字母.
//区位表第一部份,按拼音字母排序的.
//16区-55区
/*
'A'=0xB0A1, 'B'=0xB0C5, 'C'=0xB2C1, 'D'=0xB4EE, 'E'=0xB6EA, 'F'=0xB7A2, 'G'=0xB8C1,'H'=0xB9FE,
'J'=0xBBF7, 'K'=0xBFA6, 'L'=0xC0AC, 'M'=0xC2E8, 'N'=0xC4C3, 'O'=0xC5B6, 'P'=0xC5BE,'Q'=0xC6DA,
'R'=0xC8BB, 'S'=0xC8F6, 'T'=0xCBFA, 'W'=0xCDDA, 'X'=0xCEF4, 'Y'=0xD1B9, 'Z'=0xD4D1
*/
private static $FirstTable = array(
0xB0C5, 0xB2C1, 0xB4EE, 0xB6EA, 0xB7A2, 0xB8C1, 0xB9FE, 0xBBF7, 0xBFA6, 0xC0AC, 0xC2E8,
0xC4C3, 0xC5B6, 0xC5BE, 0xC6DA, 0xC8BB, 0xC8F6, 0xCBFA, 0xCDDA, 0xCEF4, 0xD1B9, 0xD4D1,0xD7FA
);
private static $FirstLetter = "ABCDEFGHJKLMNOPQRSTWXYZ";
//区位表第二部份,不规则的,下面的字母是每个区里面对应字的拼音首字母.从网上查询整理出来的,可能会有部份错误.
//56区-87区
private static $SecondTable = array(
"CJWGNSPGCGNEGYPBTYYZDXYKYGTZJNMJQMBSGZS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转换成GB2312字符,这里只是简单的判断并不是很准确,可以自己写一个.
{
if (mb_check_encoding($string,'gb2312'))
return $string;
if (function_exists('iconv'))
return iconv("utf-8","gb2312//IGNORE",$string);
return mb_convert_encoding($string,'gb2312','utf-8');
}
public static function conv($str)
{
$str = self::utf8_to_gbk($str);
$len = strlen($str);
$newStr = '';
for($i=0; $i$len ; ++$i)
{
$H = ord($str[$i]);
$L = ord($str[$i+1]);
//字符集非法
if ($H 0xB0 || $L 0xA1 || $H 0xF7 || $L == 0xFF)
{
$newStr .= $str[$i];
continue;
}
if ($H 0xD8)//($H = 0xB0 $H =0xD7)//查询文字在一级汉字区(16-55)
{
$W = ($H 8) | $L;
foreach(self::$FirstTable as $key=$value)
{
if ($W $value)
{
$newStr .= self::$FirstLetter[$key];
break;
}
}
}
else// if (H = 0xD8 H = 0xF7)//查询中文在二级汉字区(56-87)
$newStr .=self::$SecondTable[$H - 0xD8][$L-0xA1];
++$i;
}
return $newStr;
}
}
echo zh2py::conv('妃');//F
使用explode就可以,例如:
?php
$s='阿a,啊a,茬cha,茶cha,嵖cha';
foreach(explode(',',$s) as $code){
$ch=substr($code,0,2);
$code=substr($code,2);
echo "$ch\t$codebr\n";
}
?
你使用的模版技术吧。
模版技术实际上是把页面中所有 {?$pinyin?} 转换 为 ?php $pinyin ?对吧?
也就是把{? 转换为 ?php
把?}转换为 ? 。
有可能是你的{? 或 ?}也页面中的function {}冲突。
比如
......
return $restr;
}?
你的模版页面我没看到~所以不确定是不是这个问题。你可以换个模版标识试试。
如果在其他页面中function可以使用,说明这个function没问题,你就在模版页下手就行了。
PHP str_ireplace() 函数使用一个字符串替换字符串中的另一些字符。
?php
$find = "anyang";
$replace = "安阳";
$arr = "anyang测试anyang";
$newstr = str_ireplace($find,$replace,$arr);
echo $newstr;
?
使用这个str_ireplace()就能替换了,而且还不用担心大小写问题,如果不用考虑大小写那就使用str_replace()即可!
参数如下:
str_ireplace(find,replace,string,count)
参数 描述
find 必需。规定要查找的值。
replace 必需。规定替换 find 中的值的值。
string 必需。规定被搜索的字符串。
count 可选。一个变量,对替换数进行计数。
欢迎采纳!