×ãÇòÓÎÏ·_Öйú×ã²ÊÍø£¤ÌåÓý×ÊѶ$

PHPÖÐÎÄÂÒÂë½â¾ö·½°¸
À´Ô´£ºÒ×ÏÍÍø ÔĶÁ£º748 ´Î ÈÕÆÚ£º2015-03-09 15:54:15
ÎÂÜ°Ìáʾ£ºÒ×ÏÍÍøС±àΪÄúÕûÀíÁË¡°PHPÖÐÎÄÂÒÂë½â¾ö·½°¸¡±,·½±ã¹ã´óÍøÓѲéÔÄ£¡

PHP+MYSQL×öÍøÕ¾¿ª·¢Í¨³£¶¼»áÅöµ½ä¯ÀÀÆ÷Êä³öÖÐÎÄ×Ö·ûʱÂÒÂ룬Õâ¸öÎÊÌâµÄÔ­ÒòÖ÷ÒªÊÇÒòΪHTMLÄÚÈݱàÂ룬PHPÎļþ±àÂëºÍMySQLÊý¾Ý¿â±àÂëÕâÈýÕß²»Ò»ÖÂÔì³ÉµÄ¡£½ñÌìÎÒÃÇÀ´¾ßÌå̽ÌÖϳöÏÖÖÐÎÄÂÒÂëºóµÄ½â¾ö·½°¸¡£

ºº×ÖÂÒÂëÕæÊÇÒ»¸ö±¯´ßµÄÊÂÇ飬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ÖÐÎÄÂÒÂëµÄ½éÉÜÁË£¬Ï£Íû´ó¼ÒÄܹ»Ï²»¶¡£

Öйú×ã²ÊÍøÐÅÏ¢Çë²é¿´IT¼¼ÊõרÀ¸

Öйú×ã²ÊÍøÐÅÏ¢Çë²é¿´ÍøÂç±à³Ì
Ò×ÏÍÍøÊÖ»úÍøÕ¾µØÖ·£ºPHPÖÐÎÄÂÒÂë½â¾ö·½°¸
ÓÉÓÚ¸÷·½ÃæÇé¿öµÄ²»¶Ïµ÷ÕûÓë±ä»¯£¬Ò×ÏÍÍøÌṩµÄËùÓп¼ÊÔÐÅÏ¢ºÍ×Éѯ»Ø¸´½ö¹©²Î¿¼£¬¾´Ç뿼ÉúÒÔȨÍþ²¿ÃŹ«²¼µÄÕýʽÐÅÏ¢ºÍ×ÉѯΪ׼£¡

2025¹ú¿¼¡¤Ê¡¿¼¿Î³ÌÊÔÌý±¨Ãû

  • ±¨°àÀàÐÍ
  • ÐÕÃû
  • ÊÖ»úºÅ
  • ÑéÖ¤Âë
¹ØÓÚÎÒÃÇ | ÁªÏµÎÒÃÇ | È˲ÅÕÐƸ | ÍøÕ¾ÉùÃ÷ | ÍøÕ¾°ïÖú | ·ÇÕýʽµÄ¼òÒª×Éѯ | ¼òÒª×ÉѯÐëÖª | ¼ÓÈëȺ½»Á÷ | ÊÖ»úÕ¾µã | ͶËß½¨Òé
¹¤ÒµºÍÐÅÏ¢»¯²¿±¸°¸ºÅ£ºµáICP±¸2023014141ºÅ-1 ×ãÇòÓÎÏ·_Öйú×ã²ÊÍø£¤ÌåÓý×ÊѶ$ µá¹«Íø°²±¸53010202001879ºÅ ÈËÁ¦×ÊÔ´·þÎñÐí¿ÉÖ¤£º£¨ÔÆ£©ÈË·þÖ¤×Ö£¨2023£©µÚ0102001523ºÅ
ÔÆÄÏÍø¾¯±¸°¸×¨ÓÃͼ±ê
ÁªÏµµç»°£º0871-65099533/13759567129 »ñÈ¡ÕÐƸ¿¼ÊÔÐÅÏ¢¼°×Éѯ¹Ø×¢¹«Öںţºhfpxwx
×ÉѯQQ£º526150442£¨9:00¡ª18:00£©°æȨËùÓÐ:Ò×ÏÍÍø
ÔÆÄÏÍø¾¯±¨¾¯×¨ÓÃͼ±ê