I have this set of code which may randomly read a webpage and output the page title to the user, depending on what they input in the url field, it might be an English site, Chinese, Russian or whatever. But the problem is it keeps on displaying garbled text: ¹ù¸»³Ç - Google ËÑË÷
Anyone have idea is greatly appreciated.
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$DOM = new DOMDocument('1.0', 'UTF-8');
if( !@$DOM->loadHTMLFile( 'http://www.google.com.sg/search?hl=zh-CN&biw=1366&bih=636&q=%E9%83%AD%E5%AF%8C%E5%9F%8E&oq=%E9%83%AD%E5%AF%8C%E5%9F%8Ea&aq=f&aqi=g10&aql=undefined&gs_sm=e&gs_upl=6545l6545l0l1l1l0l0l0l0l295l295l2-1l1aa' ) ) {
die('cannot load!');
}
else {
$XPath = new DOMXPath( $DOM );
$title = strip_tags( $XPath->query('//title')->item(0)->nodeValue );
echo $title; exit;
}
?>