在网上看到有很多关于截取中文字符串的一些函数,在此本文章就为各位整理一下这些常用的截取中文字符串的例子吧,希望例子能帮助到大家哦。
常用的php函数
strstr(string,string) //从前面第一次出现某个字符串的地方截取到最后
strrchr(string,string) //从某个字符串从最后出现的位置截取到结尾
strpos(string,string[,int]) //某个字符串第一次出现的位置
strrpos(string,string) //某个字符串最后一次出现的位置
substr(string,int[,int]) //从指定位置开始截取字符串,可以指定截取的长度。
strlen(string) //获取字符串的长度PHP截取开始和结束标记间的字符
方法一:利用explode对字符串进行分
代码如下 | 复制代码 |
/** |
方法二:利用substr截取字符,由于php组件函数,因此字符串处理效率比explode方法要高一些
代码如下 | 复制代码 |
/**
|
PHP截取所有符合起始与结束标记的字符串
代码如下 | 复制代码 |
function get_string_between($string, $start, $end){ |
php截取起始与结束标记间字符,带截取次数、是否允许重复选项
代码如下 | 复制代码 |
/** function get_string_between($string, $start, $end){ |
截取GB2312中文字符串
代码如下 | 复制代码 |
//截取中文字符串 |
截取utf8编码的多字节字符串
代码如下 | 复制代码 |
//截取utf8字符串 |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software