DeTechn Blog

PHP将中文字符分割为单个并加上需要的字符

<?php
/**
     * 自动分类 根据关键字
     */
    public function fenlei(){
        $arr = array();
        $arr[1] = array("钱包","卡包","方包");
        $arr[2] = array("包包","双肩包","单肩包","斜挎包","行李");
        $arr[3] = array("皮带","腰带");
        $arr[4] = array("外套","西服","衣服","服装","短袖");
        $arr[5] = array("鞋");
        $arr[6] = array("眼镜","围巾","帽","手套","项链","香水","口红");
        $arr[7] = array("表");

        $result = array();
        // 将每个都以%分割
        foreach ($arr&nbsp;as&nbsp;$k=> $vo){
            foreach ($vo&nbsp;as&nbsp;$k2=>$vo2){
                $str ="%";
                for($i&nbsp;=&nbsp;0;&nbsp;$i<mb_strlen($vo2);$i++){
                    $str&nbsp;&nbsp;.=&nbsp;mb_substr($vo2,0+$i,1,'utf-8') . "%";
            }
            $result[$k][$k2]&nbsp;=&nbsp;$str;
            }
        }
        dump($result);
    }
?>

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »