Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | Email

3.2. Array 数组

数据相关函数

3.2.1. 删除数组元素

$a[]="a1";
$a[]="a2";
$a[]="a3";
print_r($a);
unset($a[1]);
print_r($a);
		

3.2.2. 数组与字符串操作

implode(separator,array)

		
<?php
$arr = array('Hello','World!');
echo implode(" ",$arr);
?>
		
		

explode(separator,string,limit)

		
<?php
$str = "Hello world!";
print_r (explode(" ",$str));
?>
		
		

3.2.3. iconv

$str = iconv('UTF-8', 'GB2312', unescape(isset($_GET['str'])? $_GET['str']:''));
报错:iconv() : Detected an illegal character in input string		
		
//TRANSLIT 会自动将不能直接转化的字符变成一个或多个近似的字符,
//IGNORE 会忽略掉不能转化的字符,而默认效果是从第一个非法字符截断。

$str = iconv('UTF-8', 'GBK//IGNORE', unescape(isset($_GET['str'])? $_GET['str']:''));	
		

替代方案

$content = iconv("GBK", "UTF-8", $content);
$content = mb_convert_encoding($content, "UTF-8", "GBK");			
		
comments powered by Disqus