2012-07-20 97 views
0

我有一個簡單的數據:image1在php中發佈數據時出現錯誤字符?

<form action="index.php" method="post"> 
<input type="text" name="name" value="3602s,5300,5300XM,6126,6131,6131 NFC,6133," /> 
<input type="submit" name="submit" value="submit" /> 
</form> 

的index.php

if($_POST['name']){ 
    echo $_POST['name']; 
} 

當我回聲$ _ POST [ '名']的結果是:

image2

如何我是否修復這個錯誤?

+0

看起來像一個編碼的問題,但我不知道在哪裏 – 2012-07-20 15:09:08

+0

是來自你的數據? – 2012-07-20 15:20:15

回答

7

在您的數據中,您有,這不是一個普通的逗號(,)字符。

這實際上是ASCII 239,其後是ASCII 188和ASCII 140(不知道爲什麼它計爲3個字符),而不是ASCII 44(正常逗號)。

要更換這一點,你可以嘗試:

$_POST['name'] = str_replace(chr(239).chr(188).chr(140), ',', $_POST['name']); 

例子:http://codepad.org/6xkIFBDL

+1

+1很好的捕獲。你是怎麼看到這個的? – iambriansreed 2012-07-20 15:09:58

+0

耶,我也是對的,這是一個編碼問題,剛剛沒有看到它在第一眼 – 2012-07-20 15:10:00

+0

+1。 – 2012-07-20 15:10:11