//////////////////////////////////////////////////////////// <dict> <key>content</key> <lang>ec</lang> <audio>http://dict.cn/mp3.php?q=MZuye</audio> <pron>kən'tent</pron> <def>n. 内容,目录,含量 a. 满足的,满意的,意义的 v. 使...满足,使...安心</def> <sent><orig>We can't go abroad this year, so we'll have to content ourselves with a holiday in Shanghai.</orig><trans>今年我们不能出国,所以只能去上海度假了。</trans></sent> <sent><orig>He is quite content with his present fortune.</orig><trans>他对自己目前的境遇颇为得意。</trans></sent><sent><orig>I like the style of his writing but I don't like the content.</orig><trans>我喜欢他的写作风格,但是不喜欢他的内容。</trans></sent> </dict>////////////////////////////////////////////////////////////# --解析 XML -------------------- $XML_URL="http://asdfasdfasdfasdfasdf";
在PHP加载XML文件那样,参数是你的URL,不就行了???
header("Content-Type: text/html;");
$word=addslashes($_GET["q"]);
$url="http://dict.cn/ws.php?q=".$word;
$contents=@file_get_contents($url);
echo $contents;
?>
<dict>
<key>content</key>
<lang>ec</lang>
<audio>http://dict.cn/mp3.php?q=MZuye</audio>
<pron>kən'tent</pron>
<def>n. 内容,目录,含量
a. 满足的,满意的,意义的
v. 使...满足,使...安心</def>
<sent><orig>We can't go abroad this year, so we'll have to content ourselves with a holiday in Shanghai.</orig><trans>今年我们不能出国,所以只能去上海度假了。</trans></sent>
<sent><orig>He is quite content with his present fortune.</orig><trans>他对自己目前的境遇颇为得意。</trans></sent><sent><orig>I like the style of his writing but I don't like the content.</orig><trans>我喜欢他的写作风格,但是不喜欢他的内容。</trans></sent>
</dict>////////////////////////////////////////////////////////////# --解析 XML -------------------- $XML_URL="http://asdfasdfasdfasdfasdf";
$db = @$doc->load($XML_UR);
if ($db){ $dictArray = $doc->getElementsByTagName("dict");
//print_r($orders-getElementsByTagName("on_qty"));
foreach( $dictArray as $dict ) {
$key = $dict->getElementsByTagName("key");
$key = utf8_decode($key->item(0)->nodeValue); $lang = $dict->getElementsByTagName("lang");
$lang = utf8_decode($lang->item(0)->nodeValue);
.....
}
}#----------------------------
<?php
$XML_URL="http://dict.cn/ws.php?q=text";
$db = @$doc->load($XML_URL);
if ($db){ $dictArray = $doc->getElementsByTagName("dict");
//print_r($orders-getElementsByTagName("on_qty"));
foreach( $dictArray as $dict ) {
$key = $dict->getElementsByTagName("key");
$key = utf8_decode($key->item(0)->nodeValue); $lang = $dict->getElementsByTagName("lang");
$lang = utf8_decode($lang->item(0)->nodeValue);
}
}
?>
老大费心了,可为啥还取不到东西?
$sent1 = utf8_decode($sent1->item(0)(orig)->nodeValue)
$sent2 = $dict->getElementsByTagName("sent");
$sent2 = utf8_decode($sent2->item(1)(orig)->nodeValue)好像有点想当然了! 你可以试一下!!!