Home > Backend Development > PHP Tutorial > substr() function Chinese version_PHP tutorial

substr() function Chinese version_PHP tutorial

WBOY
Release: 2016-07-21 16:09:29
Original
1085 people have browsed it


substr() function Chinese version The ordinary substr() function can obtain a substring of a specified length of a string, but when encountering Chinese, garbled characters may be generated at the end of the new string. The following function converts a string longer than $len into a string with "... "End, and remove the garbled characters.

Usage: $new = getsubstring($old,20);

function getsubstring($str,$len)
{
for($i = 0;$i <$end;$i++)
{
if ($i >=0 AND $i <$end)
{
if(ord(substr($str,$i, 1)) > 0xa1)
$result_str.=substr($str,$i,2);
else
$result_str.=substr($str,$i,1);
}
                                                                                                                                                  🎜>          return $result_str;                                               



http://www.bkjia.com/PHPjc/314531.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/314531.htmlTechArticlesubstr() function Chinese version The ordinary substr() function can obtain the specified length substring of a string, but When encountering Chinese, garbled characters may be generated at the end of the new string. The following function will exceed...
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