Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the php interception string functions that support Chinese and other encodings

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

The main content of this article is to explain "what are the php intercept string functions that support Chinese and other codes", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the php intercept string functions that support Chinese and other codes.

A simple string interception method that supports Chinese and other encodings. Just pass in the corresponding parameters and call them directly.

The copy code is as follows:

/ * *

* string interception, which supports Chinese and other encodings

* @ static

* @ access public

* @ param string $str string to be converted

* @ param string $start start position

* @ param string $length intercept length

* @ param string $charset encoding format

* @ param string $suffix truncate display characters

* @ return string

, /

Function msubstr ($str, $start=0, $length, $charset= "utf-8", $suffix=true) {

If (function_exists ("mb_substr"))

$slice = mb_substr ($str, $start, $length, $charset)

Elseif (function_exists ('iconv_substr')) {

$slice = iconv_substr ($str,$start,$length,$charset)

If (false = = $slice) {

$slice =''

}

} else {

$re ['utf-8'] = "/ [\ x01 -\ x7f] | [\ xc2-\ xdf] [\ x80 -\ xbf] | [\ xe0-\ xef] [\ x80 -\ xbf] {2} | [\ xf0-\ xff] [\ x80 -\ xbf] {3} /"

$re ['gb2312'] = "/ [\ x01 -\ x7f] | [\ xb0-\ xf7] [\ xa0-\ xfe] /"

$re ['gbk'] = "/ [\ x01 -\ x7f] | [\ x81 -\ xfe] [\ x40 -\ xfe] /"

$re ['big5'] = "/ [\ x01 -\ x7f] | [\ x81 -\ xfe] ([\ x40 -\ x7e] |\ xa1-\ xfe]) /"

Preg_match_all ($re [$charset], $str, $match)

$slice = join ("", array_slice ($match [0], $start, $length))

}

Return $suffix? $slice.'...': $slice

}

At this point, I believe you have a deeper understanding of "what are the php intercept string functions that support Chinese and other codes?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report