---
title: "iconv"
author: "tgxz2000"
date: "2010-12-18T11:15:41Z"
tags: []
categories: ["编程语言"]
slug: "iconv"
draft: false
lastmod: "2010-12-18T11:15:41Z"
id: 846154
url: "https://php360.iteye.com/blog/846154"
---

iconv命令可以将一种已知的字符集文件转换成另一种已知的字符集文件。

iconv -- Convert string to requested character encoding

string iconv ( string in\_charset, string out\_charset, string str )

Performs a character set conversion on the string str from in\_charset to out\_charset. Returns the converted string or FALSE on failure.

If you append the string //TRANSLIT to out\_charset transliteration is activated. This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character.

例子  iconv() example:

&lt;?php  
echo iconv("UTF-8", "GB2312", "This is a test.");//把UTF-8编码的“This is a test.”转换成GB2312编码  
?&gt;