求助關於PHP轉換漢字為UTF符的問題

2021-08-13 12:22:47 字數 3682 閱讀 9199

1樓:匿名使用者

這樣改試試.

注釋掉這段

/*if($value < 223)else

*/然後把這行$str[$i] = "\u".strtoupper(bin2hex(iconv("utf-8","ucs-2",$str[$i])));

拿出到底下.

********************====

改完如下:

<?php

function escape($str) |[\xf0-\xff][\x80-\xbf]

|[\x01-\x7f]+/e",$str,$r);

//匹配utf-8字元,

$str = $r[0];

//var_dump( $str);

$l = count($str);

for($i=0; $i<$l; $i++)else*/

$str[$i] = "\u".strtoupper(bin2hex(iconv("utf-8","ucs-2",$str[$i])));

}return join("",$str);

}$;

$url= escape(iconv('gb2312','utf-8',$title));

echo $url;

?>

2樓:匿名使用者

先用 "-" 用轉換成− 表示再轉換

php怎麼把經過utf-8編碼的中文字元轉換成正常的中文

3樓:匿名使用者

首先,baiutf-8編碼的中文字du符也是正常的。zhi如果你認為 gb2312 才「正常」dao, 可以這樣版:

$utf8_str = '中文'; // 注意這兒得是權 utf-8 編碼的字串

$gb2312_str = mb_convert_encoding($str, 'gb2312', 'utf-8');

%e5%90%89%e6%9e%97

有人已經回答了,

用 urldecode 就行了。

4樓:

<?

$a=urldecode("%e5%90%89%e6%9e%97");

$a=mb_convert_encoding($a, 'gb2312', 'utf-8');

echo $a;

?>

5樓:匿名使用者

用mb_convert_encoding函式轉換,你要說明就看下面:

string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )

converts the character encoding of string str to to_encoding from optionally from_encoding

也可以用iconv,但這個函式有些情況會出錯你這個不是版utf-8編碼,用urldecode來解碼,你試試權

6樓:匿名使用者

$file="你的字";

$text = mb_convert_encoding("$file", "gbk", "utf-8");

就是這樣。

在echo出來 $text

7樓:du瓶邪

:<%

key=request("key")

dim s

dim t

dim i

dim jjjj

dim h

dim l

dim ***x

s=""

***x=len(key)

for i =1 to ***x

t = mid(key,i,1)

jjjj = asc(t)

if jjjj> 0 then

if f then

s = s & "%" & right("00" & hex(asc(t)),2)

else

s = s & t

end if

else

if jjjj < 0 then jjjj = jjjj + &h10000

h = (jjjj and &hff00) \ &hff

l = jjjj and &hff

s = s & "%" & hex(h) & "%" & hex(l)

end if

next

set rs=server.createobject("adodb.recordset")

rs.open sql,conn,1,1

%>

php中如何把乙個字串轉換為utf-8編碼的 ?如題 謝謝了

8樓:匿名使用者

1、把 gbk 編碼字串轉換成 utf-8 編碼字串 view plaincopy to clipboardprint? <?php header("content-type:

text/html; charset=utf-8"); echo mb_convert_encoding("你是我的好朋友","utf-8","gbk"); ?> 2、把 utf-8 編碼字串轉換成 gb2312 編碼字串 view plaincopy to clipboardprint? // 注意將此檔案存檔成 utf-8 編碼格式檔案再測試 <?

php header("content-type:text/html;charset=gb2312"); echo mb_convert_encoding("你是我的好朋友","gb2312","utf-8"); ?> // 注意將此檔案存檔成 utf-8 編碼格式檔案再測試 <?

php header("content-type: text/html; charset=gb2312"); echo mb_convert_encoding("你是我的好朋友","gb312","utf-8"); ?> 3、對整個頁面進行轉換 該方法適用所有編碼環境。

這樣把前128個字元以外(顯示字元)的字符集都用 ncr(numeric character reference,如「漢字」將轉換成「漢字」這種形式)來表示,這樣的編碼在任意編碼環境下頁面都能正常顯示。 在php檔案的頭部加上下面三行**: view plaincopy to clipboardprint?

mb_internal_encoding(」gb2312″); // 這裡的gb2312是你**原來的編碼這裡的gb2312是你**原來的編碼使用mb_convert_encoding 函式需啟用php 的mbstring (multi-byte string)擴充套件

9樓:粉蒙

在網頁頭,加上這個:

PHP數字大小寫轉換求乙個php數字小寫轉為大寫的函式線上等,謝謝

function daxie number elseelseelse if substr number,1,1 內 0 return result.echo daxie 7 echo daxie 11 只能是兩位的容 先把他賦給乙個陣列,然後用array flip之類的陣列操作函式,取值,可以取回索...

php的問題,php中關於 php 的語法問題 。

是陣列成員訪問符號 是物件成員訪問符號 比如 array array site map map.php 定義了乙個陣列,包含乙個陣列成員 鍵名為site map,值為map.php this name value this 在php語言裡是個特定的變數,它代表了類本身,是訪問其類成員的操作符,thi...

關於php配置問題,為什麼我配置好php和apache之後

新手推薦使用phpnow這種整合包 建議用phpnow 或者是 wamp 這種整合的配置環境。很方便。呵呵 你的專案沒有放到apache配置好的目錄下,apache預設目錄 htdoc www 我在php mysql apache 配置好了,開啟網頁輸入localhost test.php顯示如下 ...