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

字符串的无乱码截取

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:39:18
Original
969 people have browsed it

适用于文章的分页截取,和文章标题,商品标题的截取 ?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;
	}
Copy after login

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
Latest Issues
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template