Code
<? PHP
$ URL = " Http://dict.cn/ws.php? Q = content " ;
$ Dom = New Domdocument ();
$ Dom -> Load ( $ URL );
// Print "<PRE> ";
// Print ($ dom-> savexml ());
$ Dictarray = $ Dom -> Getelementsbytagname ( " Dict " );
Foreach ( $ Dictarray As $ Dict ){
$ Key = $ Dict -> Getelementsbytagname ( " Key " );
$ Key = $ Key -> Item ( 0 ) -> Nodevalue;
$ Key = Iconv ( " UTF-8 " , " Gb2312 " , $ Key ); // Note that transcoding is required for Chinese, because XML is in UTF-8 format by default
Echo ( " * ** Output> key> content :****: " . $ Key );
$ Lang = $ Dict -> Getelementsbytagname ( " Lang " );
$ Lang = Utf8_decode ( $ Lang -> Item ( 0 ) -> Nodevalue );
Echo " <Br> " ;
Echo ( " * ** Output> Lang> content :****: " . $ Lang );
}
?>
Customer Feedback aboveCodeBlank. Apache reports the following error logs:
PHP Parse error: Parse error, unexpected t_object_operator in/var/www/vhosts/xxh.com/httpdocs/test.php on line 11
Content-Type: text/html
X-powered-by: PHP/4.3.9
Later, it was uploaded to php5.1 and found that it was normal.
PHP 4.3.9 Problems
PHP 5.1.6 (CLI) No problem