我正在建立一个解析西班牙字典的网站。如果您查找单词HOLA,您将收到定义,但换句话说,您会收到建议,例如CASA:http://verbum.xtrweb.com/verbumpost.php?word0=hola&word-1=casa
我希望:当您点击建议时(例如我上面发布的示例中的CASAR)将结果打印在像HOLA这样的div中。这是我目前使用的代码:
$words = array('word0','word-1');
function url_decode($string){
return urldecode(utf8_decode($string));
}
$baseUrl = 'http://lema.rae.es/drae/srv/search?val=';
$cssReplace = <<<EOT
<style type="text/css">
// I changed the style
</style>
</head>
EOT;
$resultIndex = 0;
foreach($words as $word) {
if(!isset($_REQUEST[$word]))
continue;
$contents = file_get_contents($baseUrl . urldecode(utf8_decode($_REQUEST[$word])));
$contents = str_replace('</head>', $cssReplace, $contents);
$contents = preg_replace('/(search?[\d\w]+)/','http://lema.rae.es/drae/srv/search', $contents);
echo "<div style='
//style
", (++$resultIndex) ,"'>", $contents,
"</div>";
}
我开始编码,所以请耐心等待,我也尝试了一些朋友建议的DOM代码,但无法正常运行。
答案 0 :(得分:1)
到output content in a styled div,只需替换:
echo "<div style='
//style
", (++$resultIndex) ,"'>", $contents,
"</div>";
}
使用:
$divStyle = 'background: none repeat scroll 20% center transparent; margin-left: 275px; height: auto; box-shadow: 0px 0px 10px rgb(0, 0, 0) inset; border: 1px solid rgb(0, 0, 0); margin-top: 35px; padding-left: 14px; width: 793px; padding-bottom: 80px;';
//insert $divStyle as the "style" attribute
echo "<div style='" . $divStyle . "'" . (++$resultIndex) . "'>" . $contents . "</div>";
改变了两件事: