PHP Via Kelime Vida ups değiştirin

1 Cevap php

İçerik insanlar eski unicode sistemi içine Word ve yapıştırma şeyleri kullanarak edilmiştir. Ben şimdi UTF8'i gitmeye çalışıyorum.

Ancak, veri ithal üzerine ben kurtulmak değil karakterler vardır.

http://snipplr.com/view.php?codeview&id=11171 / http://stackoverflow.com/questions/1262038/how-to-replace-microsoft-encoded-quotes-in-php: Ben şu stackoverflow iplik ve düzeltme bu dize sağlanan işlevlerin hiçbiri denedim

String: Danâ??s back for more!!

Yardım?

1 Cevap

Bu durumun, ben genelde ben kelime kopya yapıştırdığınız dize ile başlar:

$str = 'Danâ’s back !';
var_dump($str);


And, going byte-by-byte in it, I output the hexadecimal code of each byte :

for ($i=0 ; $i<strlen($str) ; $i++) {
    $byte = $str[$i];
    $char = ord($byte);
    printf('%s:0x%02x ', $byte, $char);
}

Hangi bunun gibi bir çıktı verir:

D:0x44 a:0x61 n:0x6e �:0xc3 �:0xa2 �:0xe2 �:0x80 �:0x99 s:0x73 :0x20 b:0x62 a:0x61 c:0x63 k:0x6b :0x20 !:0x21 


Then, with a bit of guessing, luck, and trial-and-error, you'll find out that :

  • 0xc3 0xa2: â iki bayt uyan bir karakter
  • ve special-quote üç bayt uyan bir karakter: 0xe2 0x80 0x99

İpucu: Eğer birbirini izleyen iki özel karakterler yoksa zaman kolay ;-)


After that, it's only a matter of using str_replace to replace the correct sequence of bytes by another character ; for example, to replace the special-quote by a normal one :

var_dump(str_replace("\xe2\x80\x99", "'", $str));

Size verecektir:

string 'Danâ's back !' (length=14)