1 回答
TA贡献1810条经验 获得超4个赞
SimpleXMLElement我和这个家庭的任何人都不熟悉SimpleXML,但如果你改变以下内容
foreach($syn->synset[0]->term as $value){
echo $value. "<br>";
}
到
foreach( $syn->synset as $obj ){
foreach( $obj->term as $arr ){
foreach( $arr->attributes() as $attr => $value ) echo $attr . ' ' . $value .'<br />';
}
}
或者,更全面地说:
<?php
$keyword='kopf'; # for example...
$url = "https://www.openthesaurus.de/synonyme/search?q=". $keyword. "&format=text/xml";
$options = array('http' =>
array(
'method' => 'POST',
'header' => 'user_agent: my-site.xyz',
)
);
$context = stream_context_create( $options );
$recive = file_get_contents( $url, false, $context );
if( ( $recieve = file_get_contents( $url ) )===false ){
echo "Error fetching XML\n";
} else {
libxml_use_internal_errors(true);
$syn = new SimpleXMLElement( $recieve );
if (!$syn) {
echo "Error loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
} else {
foreach( $syn->synset as $obj ){
foreach( $obj->term as $arr ){
foreach( $arr->attributes() as $attr => $value ) echo $attr . ' ' . $value .'<br />';
}
}
}
}
?>
您应该得到一些更有意义的输出,例如:
term Haupt
term Kopf
term Caput
level fachsprachlich
term Ballon
level umgangssprachlich
term Birne
level umgangssprachlich
term Denkapparat
level umgangssprachlich
term Denkzentrum
level umgangssprachlich
term Dez
level umgangssprachlich
term Kopp
level umgangssprachlich
term Murmel
level umgangssprachlich
term Nischel
level umgangssprachlich
term Nuss
level umgangssprachlich
term Omme
level umgangssprachlich
term Rübe
level umgangssprachlich
term Schädel
level umgangssprachlich
term Anführer
term Führer
term Häuptling
term Hauptmann
term (führender) Kopf
term Leiter
term Oberhaupt
term Capo (einer Ultra-Gruppe)
level fachsprachlich
term Chef
level umgangssprachlich
- 1 回答
- 0 关注
- 161 浏览
添加回答
举报