Home >php教程 >php手册 >字符串的无乱码截取

字符串的无乱码截取

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 19:39:18953browse

适用于文章的分页截取,和文章标题,商品标题的截取 ?php//字符串的无乱码截取function sub ($str,$len) {$string = '';for( $i=0; $i $len; $i++ ){if( ord(substr($str, $i,1))0xa0 ){$string .= substr($str,$i,3); //默认采用utf编码,汉字3个字节$i=$i+

适用于文章的分页截取,和文章标题,商品标题的截取

<?php
//字符串的无乱码截取
function sub ($str,$len) {
		$string = '';
		for( $i=0; $i < $len; $i++ ){
			if( ord(substr($str, $i,1))>0xa0 ){
				$string .= substr($str,$i,3);    //默认采用utf编码,汉字3个字节
				$i=$i+2;
			}else{
				$string .= substr($str,$i,1);
			}
		}
		return $string;
	}

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