Google 그룹스는 더 이상 새로운 유즈넷 게시물 또는 구독을 지원하지 않습니다. 과거의 콘텐츠는 계속 볼 수 있습니다.

Screenscraping UTF-8 characters problem

조회수 2회
읽지 않은 첫 메시지로 건너뛰기

Philipp Lenssen

읽지 않음,
2007. 2. 24. 오후 3:03:1307. 2. 24.
받는사람
Hi! I'm having some problems correctly screenscraping and outputting
e.g. Chinese characters from a Google translator search result. The
output is always a garbled mess, not Chinese characters. German for
instance works fine. Thanks for any hints...!!


Some relevant parts from the PHP5:
/******************/

header ('Content-type: text/html; charset=utf-8');
...
showResult( getTranslation('bird flu', 'zh-CN'), 'Chinese' );
...


function getTranslation($q, $lang)
{
$out = '';
// the Google page is supposed to be UTF-8 too:
$in = getFileText( "http://google.com/translate_t?langpair=en|" .
urlencode($lang) . "&text=".urlencode($q) );
preg_match('/<div id=result_box dir=ltr>(.*?)<\/div>/', $in,
$out);

$translation = $out[1]; // garbled!
$translation = trim($translation);
$translation = utf8_encode($translation); // garbled with or
without this line...
return $translation;
}

/******************/

Kimmo Laine

읽지 않음,
2007. 2. 24. 오후 5:28:3407. 2. 24.
받는사람
Philipp Lenssen kirjoitti:

Seems to me what you need are the multibyte functions. You should
replace the preg_match with the multibyte compatible mb_ereg_match:

http://fi2.php.net/manual/en/function.mb-ereg-match.php

Note that mb-functions aren't included in the default installation, you
need to add them, check the instructions for installing:
http://fi2.php.net/manual/en/ref.mbstring.php

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp...@outolempi.net | Gedoon-S @ IRCnet | rot13(xv...@bhgbyrzcv.arg)

새 메시지 0개