Home  >  Article  >  php教程  >  PHP截取字符串

PHP截取字符串

PHP中文网
PHP中文网Original
2016-05-25 17:04:591222browse

PHP截取字符串

截取GB2312中文字符串
<?php
//截取中文字符串
function mysubstr($str, $start, $len) {
    $tmpstr = "";
    $strlen = $start + $len;
    for($i = 0; $i < $strlen; $i++) {
        if(ord(substr($str, $i, 1)) > 0xa0) {
            $tmpstr .= substr($str, $i, 2);
            $i++;
        } else
            $tmpstr .= substr($str, $i, 1);
    }
    return $tmpstr;
}
?>


以上就是PHP截取字符串的内容,更多相关内容请关注PHP中文网(www.php.cn)!

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
Previous article:读取ExcelNext article:jq 添加删除class