php mb_convert_encoding

php mb_convert_encoding

php mb_convert_encoding,php內置編碼轉換方法。

方法原型:string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding = mb_internal_encoding() ] )

將 string 類型 str 的字元編碼從可選的 from_encoding 轉換到 to_encoding。

基本介紹

  • 中文名:php mb_convert_encoding
  • $str:要轉換編碼的字元串
  • $encoding1:目標編碼
  • $encoding2,:原編碼,
介紹,實例1,實例2,實例3,

介紹

mb_convert_encoding( $str, $encoding1,$encoding2 )
$str,要轉換編碼的字元串
$encoding1,目標編碼,如utf-8,gbk,大小寫均可
$encoding2,原編碼,如utf-8,gbk,大小寫均可

實例1

<?php
$str='編碼';
echo mb_convert_encoding($str, "UTF-8"); //編碼轉換為utf-8
?>

實例2

<?php
$str='編碼';
echo mb_convert_encoding($str, "UTF-8", "GBK"); //已知原編碼為GBK,轉換為utf-8
?>

實例3

<?php
$str='編碼';
echo mb_convert_encoding($str, "UTF-8", "auto"); //未知原編碼,通過auto自動檢測後,轉換編碼為utf-8
?>

相關詞條

熱門詞條

聯絡我們