我正在使用简单的 HTML DOM 类进行网页抓取。问题是它会针对 unicode 字符生成奇怪的字符。
हंगामा है कà¥à¤¯à¥‚ठबरपा / अकबर इलाहाबादी
针对印地语 unicode 字符。
लेकिन इतना तो हुआ कुछ लोग
它是我的印地语文本。
当我打印屏幕输出时,它以相同的奇怪字符输出。
function getDomContent($data) {
$html = new simple_html_dom();
$html->load($data);
foreach ($html->find('table[id=content] li') as $element) {
$content[] = $element->plaintext;
}
return $content;
}
我的卷曲功能
function getContent($url) {
$timeout = 5;
$ch = curl_init();
$user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$data = getContent($url);
$content = getDomContent($data);
echo '<pre>Array Content: ' . '<br/>';
print_r($content);
die($query);