标签归档:mb_substr

PHP 截取字符串

PHP 截取字符串

1. 截取GB2312中文字符串

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

阅读全文»

mb_substr修正函数

用于不支持mb_substr的地方

// Patch in multibyte support 
if (!function_exists('mb_substr')) { 
	function mb_substr($str, $start, $len = '', $encoding="UTF-8") { 
		$limit = strlen($str); 
		for ($s = 0; $start > 0;--$start) {// found the real start[......]

阅读全文»