PHPÖÐÎÄÂÒÂë½â¾ö·½°¸_php教程-查字典教程网
PHPÖÐÎÄÂÒÂë½â¾ö·½°¸
PHPÖÐÎÄÂÒÂë½â¾ö·½°¸
发布时间:2016-12-29 来源:查字典编辑
摘要:ºº×ÖÂÒÂëÕæÊÇÒ»¸ö±¯´ßµÄÊÂÇ飬JAVAÌÖÑẺ×Ö£¬PHPÒ²²»Ï²»¶ºº×Ö£»JavaÂÒÂë×îÖ...

ºº×ÖÂÒÂëÕæÊÇÒ»¸ö±¯´ßµÄÊÂÇ飬JAVAÌÖÑẺ×Ö£¬PHPÒ²²»Ï²»¶ºº×Ö£»

JavaÂÒÂë×îÖÕʹÓÃÁËspring¸ø³öµÄ¹ýÂËÆ÷À´¹ýÂË£¬´¦´¦¹ýÂË£¬ÆäʵӰÏìÁËËٶȣ¬²»¹ýûÓа취£¬ºº×Ö¾ÍÊÇW¹úÊ×ÏȲ»¿¼ÂǵÄÊÂÇ飻

Ïë²»µ½PHPÒ²ÊÇÂÒÂë´¦´¦ÔÚ£¬µ±ÄãʹÓÃÇ×ÐÖµÜMySQLµÄʱºò£¬ºº×ÖÏÔµÃÄÇôÇ×ÇУ¬´Óδ¿¼ÂǹýËû»á±ä³ÉÌìÊ飻²»¹ýΪÁ˺ÍÆäËûÆäËû½»»¥£¬°ÑPHPµÄÊÖÉìµ½SQL SERVERµÄʱºò£¬ÂÒÂëÀ´ÁË£¬Ô­ÒòÊǵÚÈý·½ÏµÍ³ÓõÄGBK±àÂ룻

°¥£¬×ª»»°É£»

1£¬PHP×Ô´øµÄת»»º¯ÊýICONV,Ò»¸ö¸ß´óÉϵĺ¯Êý£»

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:

string iconv ( string $in_charset , string $out_charset , string $str )

ʹÓÃDEMO£º

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:

<?php

$text = "This is the Euro symbol '€'.";

echo 'Original : ', $text, PHP_EOL;

echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL;

echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL;

echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;

?>

´ó¼Ò¶¼ÍƼöµÄº¯Êý£¬²»¹ýʹÓÃÖ®ºóÎÞ·¨×ª»»£¬Ã»ÓдíÎó£¬×Ö·ûҲûÓÐת»»£¬NO!

2£¬Áí±Ùõ辶£¬»¹ÓÐÒ»¸ö´ó¼ÒÖÊÒÉЧÂʲ»¸ßµÄº¯Êý£¬²»¹ýÎÞÂÛÈçºÎ£¬ÏÈʵÏÖÔÙ¿¼ÂÇÆäËûÈý

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:

//¼ì²é¸Ãº¯ÊýÊÇ·ñ¿ÉÓÃ

echo function_exists('mb_convert_encoding');

//¼ì²âµ±Ç°±àÂë

echo mb_detect_encoding($val, "GBK, GB2312, UTF-8");

//ת»»±àÂ룬°ÑCP936(¾ÍÊÇGBK)ת»»³ÉUTF-8

$v=mb_convert_encoding ($val, "UTF-8", "CP936");

½á¹û³É¹¦ÁË;

ºÃ°É£¬ÏÈÓÃ×Å°É£¬ÎªÁËת»»Êý¾Ý¿â²éѯµÄ½á¹û¼¯£¬ÖÆ×÷Ò»¸öת»»º¯Êý£º

1£¬º¯Êý¡°ÂÒÂë¿ËÐÇ¡±£º

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:

// $fContents ×Ö·û´®

// $from ×Ö·û´®µÄ±àÂë

// $to Ҫת»»µÄ±àÂë

function auto_charset($fContents,$from='gbk',$to='utf-8'){

$from = strtoupper($from)=='UTF8'? 'utf-8':$from;

$to = strtoupper($to)=='UTF8'? 'utf-8':$to;

if( strtoupper($from) === strtoupper($to) || empty($fContents) || (is_scalar($fContents) && !is_string($fContents)) ){

//Èç¹û±àÂëÏàͬ»òÕß·Ç×Ö·û´®±êÁ¿Ôò²»×ª»»

return $fContents;

}

if(is_string($fContents) ) {

if(function_exists('mb_convert_encoding')){

return mb_convert_encoding ($fContents, $to, $from);

}else{

return $fContents;

}

}

elseif(is_array($fContents)){

foreach ( $fContents as $key => $val ) {

$_key = auto_charset($key,$from,$to);

$fContents[$_key] = auto_charset($val,$from,$to);

if($key != $_key )

unset($fContents[$key]);

}

return $fContents;

}

else{

return $fContents;

}

}

2£¬Ê¹Óãº

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:

//´òÓ¡Êä³ö²éѯ½á¹û£¨¼ÙÉèÄãµÄ½á¹û£©

$arr=array();

while($list=mssql_fetch_row($row))

{

$arr[]=$list;

}

$s=auto_charset($arr,'gbk','utf-8');

//´òÓ¡ÊÔÊÔ£¬ÔÚä¯ÀÀÆ÷ÉèÖñàÂëΪUFT-8£¬¿´Ã»ÓÐÂÒÂë

print_r($s);die();

ÒÔÉÏËùÊö¾ÍÊDZ¾ÎĹØÓÚphpÖÐÎÄÂÒÂëµÄ½éÉÜÁË£¬Ï£Íû´ó¼ÒÄܹ»Ï²»¶¡£

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类