• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

怎么将中文字符串分割成单个字符

php 搞代码 4年前 (2022-01-23) 36次浏览 已收录 0个评论

【求助】 如何将中文字符串分割成单个字符

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> $county="大中华区";  echo "<font color='red'>".$ci=iconv_strlen($county,"UTF-8")."</font>";         for($j=0;$j<$ci;$j++){            echo  $e.=iconv_substr($county,$j,$j); }

——解决方案——————–

PHP code

<?php/**************************** * subCNchar() 截取汉字 * * [$str]     [要截取的字符串] * [$start]   [截取的起始位置] * [$length]  [要截取的长度] * [$charset] [字符串编码] ****************************/function subCNchar($str, $start = 0, $length, $charset = "utf-8") {    if (strlen($str) <br /><font color='#e78608'>------解决方案--------------------</font><br /><dl class='code'>PHP code<pre class="prettyprint linenums">大中华区[User:root Time:19:21:36 Path:/home/liangdong/php]$ cat mb.php <?php/* file-encoding : utf-8*//* export LANG=zh_CN.utf-8*/$str = "大中华区";$len = mb_strlen($str, "utf-8");for ($i = 0; $i != $len; ++ $i) {        $letter = mb_substr($str, $i, 1, "utf-8");        echo $letter . PHP_EOL;}?><br /><font color='#e78608'>------解决方案--------------------</font><br /><dl class='code'>PHP code<pre class="prettyprint linenums"> $county="大中华区";$array=str_split(<mark style="color:transparent">本文来源gaodaimacom搞#^代%!码&网*</mark><pre>搞代gaodaima码

$county,2);
——解决方案——————–

探讨

PHP code

$county=”大中华区”;
$array=str_split($county,2);

array(4) {
[0] =>
string(2) “大”
[1] =>
string(2) “中”
[2] =>
string(2) “华”
[3] =>
string(2) “区”
}


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:怎么将中文字符串分割成单个字符
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址