Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Screenscraping UTF-8 characters problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Philipp Lenssen  
View profile  
 More options Feb 24 2007, 3:03 pm
Newsgroups: comp.lang.php
From: "Philipp Lenssen" <philipp.lens...@gmail.com>
Date: 24 Feb 2007 12:03:13 -0800
Local: Sat, Feb 24 2007 3:03 pm
Subject: Screenscraping UTF-8 characters problem
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;

}

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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kimmo Laine  
View profile  
 More options Feb 24 2007, 5:28 pm
Newsgroups: comp.lang.php
From: Kimmo Laine <s...@outolempi.net>
Date: Sun, 25 Feb 2007 00:28:34 +0200
Local: Sat, Feb 24 2007 5:28 pm
Subject: Re: Screenscraping UTF-8 characters problem
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ö
s...@outolempi.net | Gedoon-S @ IRCnet | rot13(xv...@bhgbyrzcv.arg)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »