Home  >  Article  >  Backend Development  >  How to solve the problem that the thinkphp interception string function cannot display the ellipses?

How to solve the problem that the thinkphp interception string function cannot display the ellipses?

WBOY
WBOYOriginal
2016-07-25 09:11:52745browse

For the situation where thinkphp’s interception string function cannot display the ellipses, you can refer to the following solutions: Open the common/extend.php page and modify the msubstr function to:

  1. function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
  2. {
  3. if(function_exists("mb_substr")) {
  4. if( $suffix)
  5. {
  6. if($str==mb_substr($str, $start, $length, $charset))
  7. {
  8. return mb_substr($str, $start, $length, $charset);
  9. }
  10. else
  11. {
  12. return mb_substr($str, $start, $length, $charset)."...";
  13. }
  14. } // bbs.it-home.org
  15. else
  16. {
  17. return mb_substr($str, $ start, $length, $charset);
  18. }
  19. }
  20. elseif(function_exists('iconv_substr')) {
  21. if($suffix)
  22. {
  23. if($str==iconv_substr($str,$start,$length, $charset))
  24. {
  25. return iconv_substr($str,$start,$length,$charset);
  26. }
  27. else
  28. {
  29. return iconv_substr($str,$start,$length,$charset)."... ";
  30. }
  31. }
  32. else
  33. {
  34. return iconv_substr($str,$start,$length,$charset);
  35. }
  36. }
  37. $re['utf-8'] = "/[x01-x7f]| [xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
  38. $re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
  39. $re['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/" ;
  40. $re['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
  41. preg_match_all($re[$charset], $str , $match);
  42. $slice = join("",array_slice($match[0], $start, $length));
  43. if($suffix) return $slice."…";
  44. return $slice;
  45. }
Copy the code

Use the above function to display the ellipsis when intercepting the string. You can test it to see the effect.



Statement:
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