有乎-价值、共享、信任

What you care about-value, sharing, trust

【php】去除字符串的其他字符只留中文

| 阅读:1972 发表时间:2020-04-21 22:52:45 技术专栏

织梦为例:

1、把函数放入common.php

 function match_chinese($chars,$encoding='utf8'){
    $pattern =($encoding=='utf8')?'/[\x{4e00}-\x{9fa5}]/u':'/[\x80-\xFF]/';
    preg_match_all($pattern,$chars,$result);
    return join('',$result[0]);
}

2、模板中使用:{dede:field  name='title' function="match_chinese(@me)"}

*文章为作者独立观点,不代表【uuuho有乎】的立场
本文由【uuuho有乎】发表并编辑,转载此文章须经作者同意,并请附上出处及本页链接。如有侵权,请联系本站删除。

Who are we?