Php 如何设置UTF-8字符串中的第n个字符?
为了获得第n个字符,您可以编写:Php 如何设置UTF-8字符串中的第n个字符?,php,string,character,Php,String,Character,为了获得第n个字符,您可以编写: mb_substr($s,$n,1); 但是如何设置第n个字符呢?像这样: $s = 'hello'; $n = 2; // first l $r = 'x'; // replace with x echo mb_substr($s, 0, $n) . $r . mb_substr($s, $n + 1); 像这样: $s = 'hello'; $n = 2; // first l $r = 'x'; // replace with x echo mb_su
mb_substr($s,$n,1);
但是如何设置第n个字符呢?像这样:
$s = 'hello';
$n = 2; // first l
$r = 'x'; // replace with x
echo mb_substr($s, 0, $n) . $r . mb_substr($s, $n + 1);
像这样:
$s = 'hello';
$n = 2; // first l
$r = 'x'; // replace with x
echo mb_substr($s, 0, $n) . $r . mb_substr($s, $n + 1);
啊,手工方式:-)谢谢。现在我想知道是否有可能加快速度(UTF-8处理成本很高,get使用一个呼叫,set使用两个)。啊,手动方式:-)谢谢。现在我想知道是否有可能加快速度(UTF-8处理非常昂贵,get使用一个调用,而set使用两个)。