PHP intercepts string (no garbled utf8)

WBOY
Release: 2016-07-25 08:55:32
Original
1302 people have browsed it
  1. /**
  2. * String interception function
  3. * by bbs.it-home.org
  4. */
  5. function msubstr($str, $start, $len) {
  6. $tmpstr = "";
  7. $strlen = $start + $len;
  8. for($i = 0; $i < $strlen; $i++) {
  9. if(ord(substr($str, $i, 1)) > 0xa0) {
  10. $tmpstr .= substr($str, $ i, 2);
  11. $i++;
  12. } else
  13. $tmpstr .= substr($str, $i, 1);
  14. }
  15. return $tmpstr;
  16. }
Copy code

>>> You may Articles of interest: PHP Chinese interception string function (very useful) Four functions for Chinese string interception in PHP php Chinese support function php Chinese interception string function PHP Chinese string flip php Chinese character interception function (for personal use) Support Chinese PHP string interception function examples php function to intercept Chinese characters (utf-8 format) Four php Chinese string interception functions php Chinese string interception php function to intercept Chinese string Solve the problem of garbled characters when PHP intercepts UTF-8 Chinese strings Function for utf8 encoded string interception A relatively comprehensive interception function (mostly used for analysis of collected content) A useful string interception function (one Chinese character counts as two characters, and one English character counts as one character) Code learning for php string interception PHP Chinese string interception function



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!