This article collects several commonly used string interception functions. This solves the problem of garbled characters in various encodings in PHP. Students in need can refer to them.
3. Both UTF-8 and GB2312 are supported Chinese character interception function<🎜>/*<🎜><🎜>Chinese character interception function supported by Utf-8 and gb2312<🎜><🎜>cut_str(string, interception length, start length, encoding);<🎜><🎜>The encoding defaults to utf-8<🎜><🎜>The starting length defaults to 0<🎜><🎜>*/<🎜>
function sysSubStr($String,$Length,$Append = false)
{
if (strlen($String) < = $Length )
{
return $String;
}
else
{
$I = 0;
while ($I < $Length)
{
$StringTMP = substr($String,$I,1);
if ( ord($StringTMP) >=224 )
{
$StringTMP = substr($String,$I,3);
$I = $I + 3;
}
elseif( ord($StringTMP) >=192 )
{
$StringTMP = substr($String,$I,2);
$I = $I + 2;
}
else
{
$I = $I + 1;
}
$StringLast[] = $StringTMP;
}
$StringLast = implode("",$StringLast);
if($Append)
{
$StringLast .= "...";
}
return $StringLast;
}
}
$String = "php100.com-- 简单、精彩、通用";
$Length = "18";
$Append = false;
echo sysSubStr($String,$Length,$Append);
?>
复制代码
/** * @package BugFree
* @version $Id: FunctionsMain.inc.php,v 1.32 2005/09/24 11:38:37 wwccss Exp $*** Return part of a string(Enhance the function substr())** @author Chunsheng Wang * @param string $String the string to cut.
* @param int $Length the length of returned string.
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
PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals.
This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati
CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu
Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems.
With a large collection of extensions for many programming languages, VS Code can be c