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

The method of intercepting function of dedecms string

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

Share

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

Editor to share with you the method of dedecms string interception function. I hope you will gain a lot after reading this article. Let's discuss it together.

How to use the dedecms string interception function?

Discussion on cn_substr_utf8 string interception function of dedecms

Recommended study: dream weaving cms

The article I saw in phpsir mainly said that there seems to be something wrong with the cn_substr_utf8 function of dedecms. Friends who study dedecms can read it.

In dedecms, the cn_substr_utf8 function goes like this

The code is as follows:

/ * utf-8 Chinese interception, single-byte intercept mode * * @ access public* @ param string $str string to be intercepted * @ param int $slen intercept length * @ param int $startdd start tag * @ return string*/if (! Function_exists ('cn_substr_utf8')) {function cn_substr_utf8 ($str, $length, $start=0) {if (strlen ($str))

< $start+1){return '';}preg_match_all("/./su", $str, $ar);$str = '';$tstr = ''; //为了兼容mysql4.1以下版本,与数据库varchar一致,这里使用按字节截取for($i=0; isset($ar[0][$i]); $i++){if(strlen($tstr) < $start){$tstr .= $ar[0][$i];}else{if(strlen($str) < $length + strlen($ar[0][$i]) ){$str .= $ar[0][$i];}else{break;}}}return $str;}} 其中 代码如下: if(strlen($str) < $length + strlen($ar[0][$i]) ) 一行可能会造成截取后多了一个字符,可以考虑改为 代码如下: if(strlen($str) < $length + strlen($ar[0][$i]) -1 ) 测试代码如下 代码如下: $f = "你好fasdfa你fasdf#e#";$pos = strpos($f,'#e#');var_dump($pos);var_dump(cn_substr_utf8($f,$pos));var_dump(cn_substr_utf82($f,$pos)); function cn_substr($str, $slen, $startdd=0){global $cfg_soft_lang;if($cfg_soft_lang=='utf-8'){return cn_substr_utf8($str, $slen, $startdd);}$restr = '';$c = '';$str_len = strlen($str);if($str_len < $startdd+1){return '';}if($str_len < $startdd + $slen || $slen==0){$slen = $str_len - $startdd;}$enddd = $startdd + $slen - 1;for($i=0;$i $startdd){$restr .= $c;} if(ord($str[$i])>

0x80) {if ($str_len > $iTun1) {$c = $str [$I]. $str [$iTun1];} $iTunes;} else {$c = $str [$I];}

If ($I > = $enddd) {if (strlen ($restr) + strlen ($c) > $slen) {break;} else {$restr. = $c restr;}} return $restr;}

Function cn_substr_utf8 ($str, $length, $start=0) {if (strlen ($str) < $start+1) {return';} preg_match_all ("/. / su", $str, $ar)

$str =''; $tstr =''

/ / in order to be compatible with the following versions of mysql4.1, consistent with database varchar, intercept for by byte is used here ($ar [0] [$I]); $ar +) {if (strlen ($tstr) < $start) {

$tstr. = $ar [0] [$I];} else {

If (strlen ($str) < $length + strlen ($ar [0] [$I])) {

$str. = $ar [0] [$I];} else {

Break;}} return $str;}

Function cn_substr_utf82 ($str, $length, $start=0) {if (strlen ($str) < $start+1) {return';} preg_match_all ("/. / su", $str, $ar)

$str =''; $tstr =''

/ / in order to be compatible with the following versions of mysql4.1, consistent with database varchar, intercept for by byte is used here ($ar [0] [$I]); $ar +) {if (strlen ($tstr) < $start) {

$tstr. = $ar [0] [$I];} else {

If (strlen ($str) < $length + strlen ($ar [0] [$I])-1) / / phpsir added-1 {

$str. = $ar [0] [$I];} else {

Break;} return $str;} after reading this article, I believe you have a certain understanding of the method of dedecms string interception function, want to know more about it, welcome to follow the industry information channel, thank you for reading!

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