专业编程基础技术教程

网站首页 > 基础教程 正文

PHP 字符集与乱码 php字符集设置

ccvgpt 2024-10-12 13:32:06 基础教程 10 ℃

?????utf-8 gb2312 gbk?????г????в??????Сд,???Сд

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

PHP 字符集与乱码 php字符集设置

???iconv?????????????

iconv ( string in_charset, string out_charset, string str )

?磺iconv("GB2312","UTF-8",$text);

???:???????????????out_charset???,????????iconv()????,???????????????????(????????????????)

??:imagettftext()????????utf-8?????

header("content-type:text/html; charset=utf-8");

?????????mysql_query("SET NAMES UTF8")

<?php

$conn=mysql_connect("localhost","root","111") or dir("?????????????".mysql_error()); //??????????????

mysql_select_db("db_database20",$conn) or die("????????????".mysql_error()); //????db_database18

mysql_query("set names utf8"); //??????????????

?>

????????????????????????

string mb_substr ( string str, int start [, int length [, string encoding]] )

???????????????????У??????

CREATE TABLE [IF NOT EXISTS] ?????? type=myisam default character set gbk collate gbk_chinese_ci;

CREATE TABLE [IF NOT EXISTS] ?????? type=myisam default character set utf8 collate utf8_general_ci;

???????????

??????????????????????Щ?????????????????Щ????????????

????? PHP ??????????????????????????

??????????????? gbk,utf8,gb2312

mb_strlen () ????????? strlen() ????????????

mb_strstr() ????????? strstr() ????????????β?????

mb_strpos() ????????? strpos() ??????????????

mb_substr() ????????? substr() ?????????????

mb_substr_count() ???????? substr_str() ?????????????????

iconv_strlen() ????????? strlen() ????????????

iconv_strpos() ????????? strpos() ??????????????

iconv_substr() ????????? substr() ????????????β?????

iconv_strrpos()????????? substr() ????????????????????????????λ??

?????ο???? ?????????????????|??????????

?????????????????|iconv

?????

<?php

setlocale(LC_ALL, 'en_US'); //???????????

echo strftime("%A %e %B %Y", time()); //?????????

echo "<br>";

setlocale(LC_ALL, 'chs'); //?????????

$dates=strftime("%A %e %B %Y", time()); //?????????

echo iconv("gb2312","utf-8",$dates); //??????????????????????????

?>

???:

???????(??????????????)?????????(?????????????)??????,????????????;

???±????????????:ANSI,??????????????,?????????ü??±???????;

window???±?????????????utf-8????????????BOM?;??utf-8?????????BOM?????????????????????????????????????utf-8????

????????к????????BOM??????????Щ??????????BOM???????PHP????????BOM?????????ü??±???utf-8???????о????????????

?????????BOM?

??? PHP|???|???|?????????BOM????

????????????NotePad++

phpDesigner8????? ?????php???????Bom?,????"???|???????|??BOM????"???,??????????,???????BOM????

??????utf-8???,????????????.

1.????????????????utf-8??BOM

???±?,???????????????"????"?utf-8

editPlus,????????"encoding"?utf-8

Notepadd++,??ctrl+A???????????????????Encoding-->Convert to UTF-8 without BOM

UEStudio??????????"???"?utf-8??BOM???????????????????

2.??PHP????<?php ?>??????????? header('Content-type : text/html; Charset=UTF-8'); ???????????utf-8

??html???(<head>??</head>???)д??<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />?????????????utf-8

3.PHP????????????????????????sql??????????′????????????????utf-8

???·?????????????? $myqli ?? $pdo ???????mysqli??pdo?????????

mysql_query('SET NAMES utf8'); // mysql ???

mysqli_query('SET NAMES utf8'); // mysqli ???

$mysqli->query('SET NAMES utf8'); // mysqli ???

$pdo->exec('SET NAMES utf8'); // PDO ???

4.????????????????????????utf8,?????У??(callate)?????utf8_general_ci,???MySQL??????utf8??????utf-8

IF NOT EXISTS `name`(

....????....

)ENGINE InnoDB DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

?????????,?????????????????????????.

Tags:

最近发表
标签列表