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

Dedecms redefines the method of intercepting words by cn_substr function

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Editor to share with you how dedecms redefines the number of words intercepted by the cn_substr function. I hope you will gain a lot after reading this article. Let's discuss it together.

How can dedecms redefine the number of words intercepted by the cn_substr function more accurately?

Dedecms's cn_substr () and cn_substr_utf8 () intercept the string ms is not allowed, usually also use the habit of cn_substr (), do not want to use what cn_substr_utf8 () to do today, now it is more accurate. Just call it according to a Chinese character with 2 bytes.

Recommended study: dream weaving cms

Method description:

First, find\ include\ helpers\ string.helper.php to replace the original 33 to 102 lines (that is, the code that defines the cn_substr () function). If you are afraid, you can back up this file first, dear.

The code is as follows:

/ * intercept strings in both Chinese and English * * @ access public * @ param string $str string to be intercepted * @ param int $cutLen intercepted length * @ param bool $cutSlashes whether to remove\ * @ param bool $addSlashes is a string intercepted by adding\ * @ param string $oDot, such as whether the three commonly used dots * @ param bool $hasHtml have html * @ return string * / if (! Function_exists ('cn_substr')) {function cn_substr ($str, $cutLen, $oDot = null, $hasHtml = false, $cutSlashes = false, $addSlashes = false) {global $cfg_soft_lang; $str = trim ($str); if ($cutSlashes) $str = stripslashes ($str); if ($hasHtml) {$str = preg_replace ("/ (\)

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

Servers

Wechat

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

12
Report