class bihua
{
var $data;
var $dataIndex;
var $dataSpecial;
var $tone;
var $head;
var $format;
var $foot;
function setTone($tone)
{
$this->tone=$tone;
}
function setFormat($head, $format, $foot)
{
$this->head=$head;
$this->format=$format;
$this->foot=$foot;
}
function find($str, $isFirst=true)
{
for ($i=0;$i<36;$i++)
{
for ($j=0;$j<5;$j++)
{
$index=strstr($this->data[$i][$j], $str);
if (!($index===false)&&($index%2==0))
return ($i+1);//($i+1).($isFirst?$this->dataIndex[$j]:"")
}
}
return " ";
}
function render($str, $ascii=false)
{
if ($ascii)
return str_replace("%1", $str, str_replace("%2", $str, $this->format));
$bihua=strstr($this->dataSpecial, $str." ")?$str:$this->find($str." ", $this->tone);
return str_replace("%1", $str, str_replace("%2", $bihua, $this->format));
}
function parse($str)
{
$output="";
$length=strlen($str);
$output.=$this->head;
for ($i=0;$i<$length;++$i)
{
if ($i==$length-1)
{
$output.=$this->render($str[$i], true);
break;
}
$code1=ord($str[$i]);
$code2=ord($str[$i+1]);
if ($code1==0x0D&&$code2==0x0A)
{
$output.=$this->foot;
$output.=$this->head;
++$i;
}
else if ($code1>=0x81&&$code1<=0xFE&&$code2>=0x40&&$code2<=0xFE&&$code2!=0x7F)
{
$output.=$this->render($str[$i].$str[$i+1]);
++$i;
}
else
$output.=$this->render($str[$i], true);
}
$output.=$this->foot;
return $output;
}
function bihua()
{
$this->tone=true;
$this->head=""; $this->format="";
$this->foot="
%2
%1
";
$this->dataIndex=array("一", "丨", "丿", "丶", "乛");
$this->dataSpecial="! " # ¥ % & ' ( ) * + , -. / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N OP Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p qr s t u v w x y z { | }  ̄ 、 。 · ˉ ˇ ¨ 〃 々 — ~ ‖ … ‘ ’ “ ” 〔 〕 〈 〉 《》 「 」 『 』 〖 〗 【 】 ± × ÷ ∶ ∧ ∨ ∑ ∏ ∪ ∩ ∈ ∷ √ ⊥ ∥ ∠ ⌒ ⊙ ∫ ∮ ≡ ≌ ≈ ∽ ∝ ≠ ≮ ≯ ≤ ≥ ∞ ∵ ∴ ♂ ♀ ° ′ ″ ℃ $ ¤ ¢ £ ‰ § № ☆ ★ ○ ● ◎ ◇ ◆ □ ■ △ ▲ ※ → ← ↑ ↓ 〓 〡 〢 〣 〤 〥 〦 〧 〨 〩 ㊣ ㎎ ㎏ ㎜ ㎝ ㎞ ㎡ ㏄ ㏎ ㏑ ㏒ ㏕ ︰ ¬ ¦ ℡ ㈱ ‐ ー ゛ ゜ヽ ヾ 〆 ゝ ゞ ﹉ ﹊ ﹋ ﹌ ﹍ ﹎ ﹏ ﹐ ﹑ ﹒ ﹔ ﹕ ﹖ ﹗ ﹙ ﹚ ﹛ ﹜ ﹝ ﹞ ﹟ ﹠ ﹡ ﹢ ﹣ ﹤ ﹥ ﹦ ﹨﹩ ﹪ ﹫ 〇 ─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏ ┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟ ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯ ┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿ ╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ";
$this->data[0][0]="一 ";
$this->data[0][4]="乙 ";
$this->data[1][0]="二 十 丁 厂 七 ";
$this->data[1][1]="卜 ";
$this->data[1][2]="八 人 入 乂 儿 九 匕 几 ";
$this->data[1][4]="刁 了 乃 刀 力 又 乜 ";
$this->data[2][0]="三 干 亍 于 亏 士 土 工 才 下 寸 丈 大 兀与 万 弋 ";
$this->data[2][1]="上 小 口 山 巾 ";
$this->data[2][2]="千 乞 川 亿 彳 个 么 久 勺 丸 夕 凡 及 ";
$this->data[2][3]="广 亡 门 丫 义 之 ";
$this->data[
php实现获取汉字笔画数_完整类代码
最新推荐文章于 2023-07-21 11:03:14 发布
这篇博客详细介绍了如何使用PHP编写一个类来计算汉字的笔画数,该类适用于姓名学或汉字研究等场景,能够帮助理解汉字结构并进行相关应用。
摘要由CSDN通过智能技术生成