PHP获取汉字笔画数功能【测试可用】
发布时间:2020-12-12 22:18:14 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解PHP获取汉字笔画数功能。供大家参考研究具体如下: 无意中看到这么个东西,用PHP得到汉字的笔画数。以类的方式实现,有那么点意思,先留下了。 tone=$tone; } function setFormat($head,$format,$foot) { $this->head=$head; $this->f
本篇章节讲解PHP获取汉字笔画数功能。分享给大家供大家参考,具体如下: 无意中看到这么个东西,用PHP得到汉字的笔画数。以类的方式实现,有那么点意思,先留下了。 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",$this->format));
$bihua=strstr($this->dataSpecial,$str." ")?$str:$this->find($str." ",$this->tone);
return str_replace("%1",$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 O P 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 q r s t u v w x y z { | }  ̄ 、 。 · ˉ ˇ ¨ 〃 々 — ~ ‖ … ‘ ' “ ” 〔 〕 〈 〉 《 》 「 」 『 』 〖 〗 【 】 ± × ÷ ∶ ∧ ∨ ∑ ∏ ∪ ∩ ∈ ∷ √ ⊥ ∥ ∠ ⌒ ⊙ ∫ ∮ ≡ ≌ ≈ ∽ ∝ ≠ ≮ ≯ ≤ ≥ ∞ ∵ ∴ ♂ ♀ ° ′ ″ ℃ $ ¤ ¢ £ ‰ § № ☆ ★ ○ ● ◎ ◇ ◆ □ ■ △ ▲ ※ → ← ↑ ↓ 〓 〡 〢 〣 〤 〥 〦 〧 〨 〩 ㊣ ㎎ ㎏ ㎜ ㎝ ㎞ ㎡ ㏄ ㏎ ㏑ ㏒ ㏕ ︰ ¬ ¦ ℡ ㈱ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |