Home > Backend Development > PHP Tutorial > 字符串截取的有关问题

字符串截取的有关问题

WBOY
Release: 2016-06-13 10:05:04
Original
706 people have browsed it

字符串截取的问题
我想截取10个字符,包括中英文
怎么才能保证:
截取出来的一定是10个字符呢?如5个英文,5个中文
4个英文,6个中文

------解决方案--------------------
$abc= "你好不朋友abc ";
$len=strlen($abc);
for ($i=0;$i if (ord(substr($abc,$i,1))> 0xa0)
{
$string.=substr($abc,$i,2);
$i++; }
else{
$abc.=substr($abc,$i,1);
}
echo $abc. "
";
}
------解决方案--------------------
$abc= "你好不朋友abc ";
$len=strlen($abc);
for ($i=0;$i if (ord(substr($abc,$i,1))> 0xa0)
{
$string.=substr($abc,$i,2);
$i++; }
else{
$string.=substr($abc,$i,1);
}
echo $string. "
";
}

------解决方案--------------------
mb_substr

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template