Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | 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");