我有一些 HTML 试图插入到数据库中,但事实证明它比我想象的要难。
HTML 看起来像这样(id 值是静态的,每个问题都有 id78questionRegion 作为 id):
<div class="fullquestion">
<div class='question'>House Frey are Bannermen sworn to which House?</div><div style=" visibility:visible; " id="id78questionRegion">
<a href="javascript:___gid_10(0)"><span>House Baratheon</span></a>
<a href="javascript:___gid_10(1)"><span>House Tyrell</span></a>
<a href="javascript:___gid_10(2)"><span>House Arryn</span></a>
<a href="javascript:___gid_10(3)"><span>House Stark</span></a>
<a href="javascript:___gid_10(4)"><span>House Tully</span></a>
</div><div class='answer'>House Tully</div>
</div>
和 PHP
<?php
$type = '';
require ($_SERVER["DOCUMENT_ROOT"] . '/inc/db.php');
require($_SERVER["DOCUMENT_ROOT"] . '/admin/simple_html_dom.php');
$file = 'qa.html';
$html = new simple_html_dom();
$html->load_file($file);
$qcount = 100;
for ($i = 0; $i <= $qcount; $i++) {
echo 'Question is:<br>';
echo $html->find('.question', $i);
echo 'Possible Answers are:<br>';
foreach ($html->find('#id78questionRegion a span', $i) as $question) {
echo $html->find('#id78questionRegion a span');
}
echo 'Answer is:<br>';
echo $html->find('.answer', $i);
}
?>
我想有一个问题,一个var中的每个可能的答案以及正确的答案,但我不知道如何正确地得到答案。任何帮助表示赞赏!
谢谢。